GetDirectories() public static method

public static GetDirectories ( string path ) : string[]
path string
return string[]
        Directory ResolveDirectory(Directory directory, IEnumerable<string> children)
        {
            if (!children.Any())
                return directory;

            string childName = children.First();

            Directory info = directory.GetDirectories()
                .Where(x => string.Compare(x.Name.GetName(), childName, true) == 0)
                .SingleOrDefault();

            if (info != null)
            {
                return ResolveDirectory(info, children.Skip(1));
            }

            File file = directory.GetFiles()
                .Where(x => string.Compare(x.Name.GetName(), childName, true) == 0)
                .SingleOrDefault();

            if (file == null)
                throw new InvalidOperationException("Could not get directory: " + childName);

            if (Path.GetExtension(file.Name.GetName()) == ".zip")
            {
                var zipFileDirectory = new ZipFileDirectory(file.Name.Name);
                return ResolveDirectory(zipFileDirectory, children.Skip(1));
            }

            throw new InvalidOperationException("Could not resolve the rest of the path: " + childName);
        }
Beispiel #2
0
    /// <summary>
    ///     Lists all the directories contained at a certain directory.
    /// </summary>
    /// <param name="path">The path of the directory.</param>
    /// <returns>
    ///     An array of directory paths.
    /// </returns>
    /// <exception cref="ArgumentNullException">
    ///     <paramref name="path" /> is <see langword="null" /> (<see langword="Nothing" />
    ///     in Visual Basic).
    /// </exception>
    public string[] GetDirectories(string path)
    {
        _ = Requires.NotNullOrWhiteSpace(
            path,
            nameof(path));

        return(FSDir.GetDirectories(path));
    }
Beispiel #3
0
    /// <summary>
    ///     Lists all the directories contained at a certain directory with a specific search pattern.
    /// </summary>
    /// <param name="path">The path of the directory.</param>
    /// <param name="searchPattern">The search pattern to use.</param>
    /// <returns>
    ///     An array of directory paths.
    /// </returns>
    /// <exception cref="ArgumentNullException">
    ///     <paramref name="path" /> or <paramref name="searchPattern" /> is
    ///     <see langword="null" /> (<see langword="Nothing" /> in Visual Basic).
    /// </exception>
    public string[] GetDirectories(
        string path,
        string searchPattern)
    {
        _ = Requires.NotNullOrWhiteSpace(
            path,
            nameof(path));
        _ = Requires.NotNullOrWhiteSpace(
            searchPattern,
            nameof(searchPattern));

        return(FSDir.GetDirectories(
                   path,
                   searchPattern));
    }
        File ResolveFile(Directory directoryInfo, IEnumerable<string> children)
        {
            if (!children.Any())
                throw new InvalidOperationException("Unable to resolve file: " + directoryInfo.Name);

            string childName = children.First();

            Directory info = directoryInfo.GetDirectories()
                .Where(x => string.Compare(x.Name.GetName(), childName, true) == 0)
                .SingleOrDefault();

            if (info != null)
            {
                return ResolveFile(info, children.Skip(1));
            }

            File file = directoryInfo.GetFiles()
                .Where(x => string.Compare(x.Name.GetName(), childName, true) == 0)
                .SingleOrDefault();

            if (file == null)
                throw new InvalidOperationException("Could not get file: " + childName);

            if (!children.Skip(1).Any())
                return file;

            //			if (Path.GetExtension(file.Name.GetName()) == ".zip")
            //			{
            //				var zipFileDirectory = new ZipFileDirectory(file.Name.Name);
            //				return ResolveFile(zipFileDirectory, children.Skip(1));
            //			}

            throw new NotImplementedException();
        }
Beispiel #5
0
        private static string[] CollectPathsFromToolbox(string toolboxRiderRootPath, string dirName, string searchPattern,
                                                        bool isMac)
        {
            if (!Directory.Exists(toolboxRiderRootPath))
            {
                return(new string[0]);
            }

            var channelDirs = Directory.GetDirectories(toolboxRiderRootPath);
            var paths       = channelDirs.SelectMany(channelDir =>
            {
                try
                {
                    // use history.json - last entry stands for the active build https://jetbrains.slack.com/archives/C07KNP99D/p1547807024066500?thread_ts=1547731708.057700&cid=C07KNP99D
                    var historyFile = Path.Combine(channelDir, ".history.json");
                    if (File.Exists(historyFile))
                    {
                        var json  = File.ReadAllText(historyFile);
                        var build = ToolboxHistory.GetLatestBuildFromJson(json);
                        if (build != null)
                        {
                            var buildDir        = Path.Combine(channelDir, build);
                            var executablePaths = GetExecutablePaths(dirName, searchPattern, isMac, buildDir);
                            if (executablePaths.Any())
                            {
                                return(executablePaths);
                            }
                        }
                    }

                    var channelFile = Path.Combine(channelDir, ".channel.settings.json");
                    if (File.Exists(channelFile))
                    {
                        var json  = File.ReadAllText(channelFile).Replace("active-application", "active_application");
                        var build = ToolboxInstallData.GetLatestBuildFromJson(json);
                        if (build != null)
                        {
                            var buildDir        = Path.Combine(channelDir, build);
                            var executablePaths = GetExecutablePaths(dirName, searchPattern, isMac, buildDir);
                            if (executablePaths.Any())
                            {
                                return(executablePaths);
                            }
                        }
                    }

                    // changes in toolbox json files format may brake the logic above, so return all found Rider installations
                    return(Directory.GetDirectories(channelDir)
                           .SelectMany(buildDir => GetExecutablePaths(dirName, searchPattern, isMac, buildDir)));
                }
                catch (Exception e)
                {
                    // do not write to Debug.Log, just log it.
                    Logger.Warn($"Failed to get RiderPath from {channelDir}", e);
                }

                return(new string[0]);
            })
                              .Where(c => !string.IsNullOrEmpty(c))
                              .ToArray();

            return(paths);
        }
Beispiel #6
0
 public async Task <IList <IFolder> > GetFoldersAsync() => await Task.Factory.StartNew(() => D.GetDirectories(Path).Select(s => (IFolder) new Folder(s)).ToList());
Beispiel #7
0
        public static void CreateInstaller(string input, string output, Func <string, bool> excludeFromCompression)
        {
            Console.Write("Creating install package " + output + " ");

            if (!input.EndsWith("\\", StringComparison.OrdinalIgnoreCase))
            {
                input += "\\";
            }
            int trimOffset = (string.IsNullOrEmpty(input) ? Path.GetPathRoot(input).Length : input.Length);

            List <string> fileSystemEntries = new List <string>();

            fileSystemEntries.AddRange(Directory.GetDirectories(input, "*", SearchOption.AllDirectories).Select(d => d + "\\"));
            fileSystemEntries.AddRange(Directory.GetFiles(input, "*", SearchOption.AllDirectories));


            using (var outputStream = new FileStream(output, FileMode.Create, FileAccess.Write, FileShare.None))
            {
                using (var compressor = new ZipOutputStream(outputStream))
                {
                    compressor.SetLevel(9);
                    var data      = new byte[4194304];
                    int milestone = fileSystemEntries.Count / 10;
                    int i         = 0;

                    foreach (var filePath in fileSystemEntries)
                    {
                        if (i++ % milestone == 0)
                        {
                            Console.Write('.');
                        }

                        if (excludeFromCompression(filePath))
                        {
                            continue;
                        }

                        if (filePath.EndsWith("\\", StringComparison.OrdinalIgnoreCase))
                        {
                            var directoryInfo = new DirectoryInfo(filePath);
                            compressor.PutNextEntry(new ZipEntry(filePath.Substring(trimOffset))
                            {
                                DateTime = directoryInfo.LastWriteTimeUtc
                            });
                            continue;
                        }
                        else
                        {
                            var fileInfo = new FileInfo(filePath);
                            compressor.PutNextEntry(new ZipEntry(filePath.Substring(trimOffset))
                            {
                                DateTime = fileInfo.LastWriteTimeUtc,
                                Size     = fileInfo.Length
                            });
                        }

                        using (var inputStream = File.OpenRead(filePath))
                        {
                            int bytesRead;
                            while ((bytesRead = inputStream.Read(data, 0, data.Length)) > 0)
                            {
                                compressor.Write(data, 0, bytesRead);
                            }
                        }
                    }
                    Console.WriteLine();
                    compressor.Finish();
                }
            }
        }
Beispiel #8
0
 public List <string> GetSubDirectories(string directoryPath)
 {
     return(Directory.GetDirectories(directoryPath, "*", SearchOption.TopDirectoryOnly).ToList());
 }