当前位置: 首页>>代码示例>>C#>>正文


C# DirectoryInfo.EnumerateDirectories方法代码示例

本文整理汇总了C#中System.IO.DirectoryInfo.EnumerateDirectories方法的典型用法代码示例。如果您正苦于以下问题:C# DirectoryInfo.EnumerateDirectories方法的具体用法?C# DirectoryInfo.EnumerateDirectories怎么用?C# DirectoryInfo.EnumerateDirectories使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.DirectoryInfo的用法示例。


在下文中一共展示了DirectoryInfo.EnumerateDirectories方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IsIgniteHome

 /// <summary>
 /// Determines whether specified dir looks like a Ignite home.
 /// </summary>
 /// <param name="dir">Directory.</param>
 /// <returns>Value indicating whether specified dir looks like a Ignite home.</returns>
 private static bool IsIgniteHome(DirectoryInfo dir)
 {
     return dir.Exists &&
            (dir.EnumerateDirectories().Count(x => x.Name == "examples" || x.Name == "bin") == 2 &&
             dir.EnumerateDirectories().Count(x => x.Name == "modules" || x.Name == "platforms") == 1)
            || // NuGet home
            (dir.EnumerateDirectories().Any(x => x.Name == "Libs") &&
             (dir.EnumerateFiles("Apache.Ignite.Core.dll").Any() ||
              dir.EnumerateFiles("Apache.Ignite.*.nupkg").Any()));
 }
开发者ID:RazmikMkrtchyan,项目名称:ignite,代码行数:15,代码来源:IgniteHome.cs

示例2: Main

    public static void Main(string[] args)
    {
      var statistics = new Dictionary<string, int>();

      IImageBinarizer binarizer = new ImageBinarizer();
      var directoryInfo = new DirectoryInfo(Environment.CurrentDirectory).Parent.Parent.Parent;
      var path = Path.Combine(directoryInfo.FullName, Program.DataDirectoryName);
      directoryInfo = new DirectoryInfo(path);

      var imageClassifier = new ImageClassifier(binarizer, Program.Size * Program.Size);
      //Train
      foreach (DirectoryInfo directory in directoryInfo.EnumerateDirectories())
      {
        foreach (var file in directory.EnumerateFiles("*.bmp"))
        {
          string fileName = Path.GetFileNameWithoutExtension(file.FullName);
          imageClassifier.Train(new ImageUnit { Id = fileName, Image = new Bitmap(file.FullName) });
        }
      }

      foreach (DirectoryInfo directory in directoryInfo.EnumerateDirectories())
      {
        foreach (var file in directory.EnumerateFiles("*.bmp"))
        {
          string fileName = Path.GetFileNameWithoutExtension(file.FullName);
          var patternDirectory = directory.EnumerateDirectories().FirstOrDefault(p => p.Name == ("Randomized_" + fileName));
          foreach (var patternFile in patternDirectory.EnumerateFiles("*.bmp"))
          {
            string patternFileName = Path.GetFileNameWithoutExtension(patternFile.FullName);
            string[] nameParts = patternFileName.Split(new[] { "_" }, StringSplitOptions.RemoveEmptyEntries);
            string percentValue = nameParts[1];
            if (statistics.ContainsKey(percentValue) == false)
            {
              statistics.Add(percentValue, 0);
            }
            string classificationResult = imageClassifier.Classify(new Bitmap(patternFile.FullName));
            if (classificationResult.Equals(fileName, StringComparison.CurrentCulture))
            {
              statistics[percentValue] += 1;
            }
          }
        }
      }

      Console.WriteLine("Classification result: ");

      foreach (var statistic in statistics)
      {
        Console.WriteLine("Percent - {0} Match - {1}", statistic.Key, statistic.Value);
      }

      Console.ReadLine();
    }
开发者ID:RamanBut-Husaim,项目名称:MiSOI,代码行数:53,代码来源:Program.cs

示例3: All

        /// <summary>
        /// Alls this instance.
        /// </summary>
        /// <returns></returns>
        public IEnumerable<DataModel.Release> All()
        {
            DirectoryInfo dir = new DirectoryInfo(Utilities.PathUtilities.MapPath(_configurationManager.HoardeBaseDirectory));
            return dir.EnumerateDirectories("*", SearchOption.TopDirectoryOnly).Select(x =>
            {
                string version = "";
                var versionMatches = VERSION_PARSER.Match(x.Name);

                if (versionMatches.Success)
                {
                    var matchedVersion = versionMatches.Groups[0];
                    version = matchedVersion.Value;
                }

                return new DataModel.Release
                {
                    CreatedOn = DateTime.Now,
                    Description = x.Name,
                    Id = x.Name.Replace(version, string.Empty).Trim('.'),
                    Version = version.Trim('.'),
                    UpdatedOn = DateTime.Now,
                    Title = x.Name,
                    Summary = string.Empty,
                    IconUrl = string.Empty,
                    Listed = true,
                    Published = DateTime.Now,
                    ReleaseNotes = string.Empty,
                    SHA1 = string.Empty,
                    Tags = string.Empty
                };
            })
            .Where(r => !r.Id.Equals(DreyConstants.ConfigurationPackageName, StringComparison.OrdinalIgnoreCase));
        }
开发者ID:dealproc,项目名称:Drey,代码行数:37,代码来源:OnDiskPackageRepository.cs

示例4: DownloadAndExtract

        /// <summary>
        /// Downloads one or more packages.
        /// </summary>
        /// <param name="packageContainer">
        /// The packageto downloaded.
        /// </param>
        /// <param name="repositoryDirectory">
        /// The directory to which to download the packages.
        /// </param>
        /// <param name="overwrite">
        /// If set to <see langword="true"/>, any existing directory will be deleted.
        /// </param>
        /// <returns>
        /// A <see cref="Task"/> that represents the asynchronous operation
        /// </returns>
        public static async Task<DirectoryInfo> DownloadAndExtract(IArchiveContainer packageContainer, DirectoryInfo repositoryDirectory, bool overwrite)
        {
            // Create the directory into which to extract
            string directoryName = $"{packageContainer.Name}-{packageContainer.Revision}";

            // Figure out whether that directory already exists.
            DirectoryInfo targetDirectory;
            targetDirectory = repositoryDirectory.EnumerateDirectories(directoryName).SingleOrDefault();

            // If it does, proceed based on the value of the overwrite flag
            if (targetDirectory != null)
            {
                if (overwrite)
                {
                    // Delete the directory & proceed as usual.
                    targetDirectory.Delete(true);
                    targetDirectory = null;
                }
                else
                {
                    // Nothing left to do.
                    return targetDirectory;
                }
            }

            targetDirectory = repositoryDirectory.CreateSubdirectory(directoryName);

            foreach (var package in packageContainer.Archives)
            {
                Console.WriteLine($"Downloading package {package.Url} for {package.HostOs}");
                await package.DownloadAndExtract(targetDirectory);
            }

            return targetDirectory;
        }
开发者ID:quamotion,项目名称:adk-nuget,代码行数:50,代码来源:PackageGenerator.cs

示例5: Visit

        public static void Visit(IFileSystemVisitor visitor, DirectoryInfo folder, bool recurse)
        {
            if (Visit(visitor, folder))
            {
                FileInfo[] fileitems;
                DirectoryInfo[] diritems;
                //try
                //{
                    fileitems = folder.EnumerateFiles().ToArray();
                    diritems = (recurse) ? folder.EnumerateDirectories().ToArray() : null;
                //}
                //catch (Exception ex)
                //{
                //    visitor.OnException(folder, ex);
                //    fileitems = new FileInfo[0];
                //    diritems = new DirectoryInfo[0];
                //}

                foreach (var file in fileitems)
                {
                    Visit(visitor, file);
                }

                Visited(visitor, folder);

                if (recurse)
                {
                    foreach (var subfolder in diritems)
                    {
                        Visit(visitor, subfolder, recurse);
                    }
                }
            }
        }
开发者ID:codetuner,项目名称:Arebis.Common,代码行数:34,代码来源:FileSystem.cs

示例6: BindData

        private void BindData()
        {
            var directoryInfo = new DirectoryInfo(baseFolder);

            gwRepos.DataSource = directoryInfo.EnumerateDirectories(string.Format("*.{0}", Git.GIT_EXTENSION), SearchOption.AllDirectories);
            gwRepos.DataBind();
        }
开发者ID:toshic,项目名称:Git-Web-Access,代码行数:7,代码来源:Repository.aspx.cs

示例7: RecurseChildDirectories

 private void RecurseChildDirectories(DirectoryInfo directory, List<FileInfo> files)
 {
     foreach (DirectoryInfo dir in directory.EnumerateDirectories())
     {
         files.AddRange(GetProjectFiles(dir));
     }
 }
开发者ID:themotleyfool,项目名称:SlimJim,代码行数:7,代码来源:ProjectFileFinder.cs

示例8: Create

        public static Tuple<DirectoryEntry, ImmutableList<ProjectEntry>> Create(DirectoryInfo dir, string relativePath)
        {
            if (relativePath == "packages")
                return new Tuple<DirectoryEntry, ImmutableList<ProjectEntry>>(PackagesEntry.Create(dir), null);

            if (relativePath != null && File.Exists(Path.Combine(dir.FullName, "project.json")))
                return ProjectEntry.Create(dir, relativePath);

            var dirsAndProjects = from d in dir.EnumerateDirectories()
                                  where !d.IsHidden()
                                  orderby d.Name
                                  select Create(d, Path.Combine(relativePath, d.Name));

            var dirs = ImmutableList.CreateBuilder<DirectoryEntry>();
            var projects = ImmutableList.CreateBuilder<ProjectEntry>();
            foreach (var dap in dirsAndProjects)
            {
                if (dap.Item2 != null)
                    projects.AddRange(dap.Item2);
                dirs.Add(dap.Item1);
            }

            var files = from f in dir.EnumerateFiles()
                        where !f.IsHidden()
                        orderby f.Name
                        select (Entry)FileEntry.Create(f, Path.Combine(relativePath, f.Name));

            return new Tuple<DirectoryEntry, ImmutableList<ProjectEntry>>(
                new DirectoryEntry(relativePath, false, dir,
                    dirs.ToImmutable(), files.ToImmutableList()),
                projects.ToImmutable());
        }
开发者ID:Runt-Editor,项目名称:Runt,代码行数:32,代码来源:DirectoryEntry.cs

示例9: PrepareDirectory

        private static void PrepareDirectory(DirectoryInfo sourcePath, DirectoryInfo targetPath)
        {
            if (!sourcePath.Exists)
            {
                throw new DirectoryNotFoundException("Source directory " + sourcePath.FullName + " does not exist.");
            }

            targetPath.Create();

            foreach (var file in sourcePath.EnumerateFiles())
            {
                var overwrite = !file.Extension.Equals("yml", StringComparison.OrdinalIgnoreCase);
                var target = Path.Combine(targetPath.FullName, file.Name);

                // If file exists and should not be directly overwritten, just remember the user to manually update the file as needed.
                if (File.Exists(target) && !overwrite)
                {
                    var oldTarget = target;
                    target += ".dist";
                    Console.Error.WriteLine(
                        "WARNING: File {0} needs a manual update! Compare with {1} and rewrite your file.", oldTarget,
                        target);
                }

                file.CopyTo(target, overwrite);
            }

            foreach (var subdirectory in sourcePath.EnumerateDirectories())
            {
                PrepareDirectory(subdirectory, targetPath.CreateSubdirectory(subdirectory.Name));
            }
        }
开发者ID:ap0110,项目名称:citizenmp-server-updater,代码行数:32,代码来源:Program.cs

示例10: RenderDirectoryTree

 protected IEnumerable<KeyValuePair<string, IEnumerable<KeyValuePair<string, string>>>> RenderDirectoryTree(DirectoryInfo rootDirectory, DirectoryInfo currentDirectory)
 {
     return currentDirectory
         .EnumerateDirectories()
         .SelectMany(directoryInfo => RenderDirectoryTree(rootDirectory, directoryInfo))
         .Concat(Enumerable.Repeat(RenderDirectoryViews(rootDirectory, currentDirectory), 1));
 }
开发者ID:duhaly,项目名称:Nancy-vNext5,代码行数:7,代码来源:Compiler.cs

示例11: print

        public string print(string path)
        {
            if (File.Exists(path))
            {
                StringBuilder sb = new StringBuilder();

                FileAttributes fas = File.GetAttributes(path);
                if ((fas & FileAttributes.Directory) == FileAttributes.Directory)
                {

                    DirectoryInfo di = new DirectoryInfo(path);
                    AppendLeaf(sb, 0, di.Name);

                    foreach (FileInfo fileInfo in di.EnumerateFiles())
                    {
                        AppendLeaf(sb, 1, fileInfo.Name);
                    }

                    foreach (DirectoryInfo dirInfo in di.EnumerateDirectories())
                    {
                        AppendLeaf(sb, 1, dirInfo.Name);
                    }

                    Console.WriteLine("Given path is directory");
                }
                else
                {
                    // is path to a file
                    AppendLeaf(sb, 0, path);
                    return sb.ToString();
                }

            }
            throw new ArgumentException("No such path exists");
        }
开发者ID:carlbradbury,项目名称:katas,代码行数:35,代码来源:PrettyPathPrinter.cs

示例12: ProcessDir

 public static void ProcessDir(DirectoryInfo directoryInfo, string outDir)
 {
     if (!Directory.Exists(outDir)) Directory.CreateDirectory(outDir);
     //
     DirectoryInfo outDirInfo = new DirectoryInfo(outDir);
     //
     // Directories:
     //
     ObsoleteDirs obsoleteDirs = new ObsoleteDirs(outDirInfo);
     foreach (DirectoryInfo subDirectoryInfo in directoryInfo.EnumerateDirectories())
     {
         obsoleteDirs.RemoveDirFromObsoleteList(subDirectoryInfo);
         //
         ProcessDir(subDirectoryInfo, Path.Combine(outDir, subDirectoryInfo.Name));
     }
     obsoleteDirs.DeleteDirs();
     //
     // Files:
     //
     ObsoleteFiles obsoleteFiles = new ObsoleteFiles(outDirInfo);
     foreach (FileInfo fileInfo in directoryInfo.EnumerateFiles())
     {
         string outFileName = processFile(fileInfo, outDir);
         obsoleteFiles.RemoveFileFromObsoleteList(outFileName);
     }
     obsoleteFiles.DeleteFiles();
 }
开发者ID:metabench,项目名称:jsgui-doc,代码行数:27,代码来源:ProcessDirHelper.cs

示例13: DeleteEmptyFolders

        private void DeleteEmptyFolders(string path)
        {
            try
            {
                foreach (var folder in Directory.EnumerateDirectories(path))
                {
                    DirectoryInfo folderInfo = new DirectoryInfo(folder);

                    foreach (var fileInfo in folderInfo.EnumerateFiles().Where(x => ext.Any(i => x.Extension != i)))
                    {
                        if (File.Exists(Path.Combine(path, fileInfo.Name))) File.Delete(Path.Combine(path, fileInfo.Name));
                        File.Move(fileInfo.FullName, Path.Combine(path, fileInfo.Name));
                    }

                    if (folderInfo.EnumerateFiles().Any()) return;
                    if (folderInfo.EnumerateDirectories().Any()) DeleteEmptyFolders(folder);

                    Directory.Delete(folder);
                    DeleteEmptyFolders(folder);
                }
            }
            catch (IOException ex)
            {
                Logger.WriteLine("An error occured while trying to delete empty folders in {0}: {1}", path, ex);
            }
        }
开发者ID:MulberryDev,项目名称:Redemption,代码行数:26,代码来源:ImageWatcher.cs

示例14: EnumerateAllJPGs

		public List<FileInfo> EnumerateAllJPGs(String Path)
		{
			List<FileInfo> Output = new List<FileInfo>();
			#region enumerate all .jpg in ./pics
			DirectoryInfo diTop = new DirectoryInfo(Path);
			foreach (var di in diTop.EnumerateDirectories("*"))
			{
				try
				{
					foreach (var fi in di.EnumerateFiles("*", SearchOption.AllDirectories))
					{
						try
						{
							if (fi.Extension.ToUpper() == ".JPG")
								Output.Add(fi);
						}
						catch (UnauthorizedAccessException UnAuthFile)
						{
						}
					}
				}
				catch (UnauthorizedAccessException UnAuthSubDir)
				{
				}
			}
			#endregion
			return Output;
		}
开发者ID:jmhdz,项目名称:GalleryServer,代码行数:28,代码来源:FileManagement.cs

示例15: GetDirectoryXml

        //main function, returns the XML of a entire directory (subdirectories included)
        internal static XElement GetDirectoryXml(String dir, string[] fileExtensions)
        {
            //Create DirectoryInfo
            DirectoryInfo Dir = new DirectoryInfo(dir);

            //Will be used to store the bad files
            List<FileInfo> BadFiles = new List<FileInfo>();

            //Will be used to store the processed files
            List<FileInfo> AlreadyProcessedFiles = new List<FileInfo>();

            //Mandatory to avoid invalid xml
            var info = new XElement("Root");

            //Gather file information
            ComputeFileInfo(Dir.EnumerateFiles().Where(f => fileExtensions.Contains(f.Extension.ToLower())).ToArray(),
                            ref info,
                            BadFiles,
                            AlreadyProcessedFiles,
                            fileExtensions);

            foreach (var subDir in Dir.EnumerateDirectories())
            {
                info.Add(GetDirectoryXml(subDir.FullName, fileExtensions));
            }

            return info;
        }
开发者ID:jaguar0076,项目名称:FileManager,代码行数:29,代码来源:ProcessXml.cs


注:本文中的System.IO.DirectoryInfo.EnumerateDirectories方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。