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


C# DirectoryInfo.EnumerateFiles方法代码示例

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


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

示例1: LoadAllToCache

        /// <summary>
        /// Dumps everything of a single type into the cache from the filesystem for BackingData
        /// </summary>
        /// <typeparam name="T">the type to get and store</typeparam>
        /// <returns>full or partial success</returns>
        public static bool LoadAllToCache(Type objectType)
        {
            if (!objectType.GetInterfaces().Contains(typeof(IData)))
                return false;

            var fileAccessor = new NetMud.DataAccess.FileSystem.BackingData();
            var typeDirectory = fileAccessor.BaseDirectory + fileAccessor.CurrentDirectoryName + objectType.Name + "/";

            if (!fileAccessor.VerifyDirectory(typeDirectory, false))
            {
                LoggingUtility.LogError(new AccessViolationException(String.Format("Current directory for type {0} does not exist.", objectType.Name)));
                return false;
            }

            var filesDirectory = new DirectoryInfo(typeDirectory);

            foreach (var file in filesDirectory.EnumerateFiles())
            {
                try
                {
                    BackingDataCache.Add(fileAccessor.ReadEntity(file, objectType));
                }
                catch(Exception ex)
                {
                    LoggingUtility.LogError(ex);
                    //Let it keep going
                }
            }

            return true;
        }
开发者ID:SwiftAusterity,项目名称:NetMud,代码行数:36,代码来源:BackingData.cs

示例2: WriteSomeFiles

        public void WriteSomeFiles()
        {
            var directory = new DirectoryInfo(tempDirectory);
            foreach (var file in directory.EnumerateFiles())
            {
                file.Delete();
            }

            var properties = new MessageProperties();
            var info = Helper.CreateMessageRecievedInfo();
            var writer = new FileMessageWriter();
            var messages = new List<HosepipeMessage>
            {
                new HosepipeMessage("This is message one", properties, info),
                new HosepipeMessage("This is message two", properties, info),
                new HosepipeMessage("This is message three", properties, info)
            };

            var parameters = new QueueParameters
            {
                QueueName = "Queue EasyNetQ_Tests_TestAsyncRequestMessage:EasyNetQ_Tests_Messages",
                MessageFilePath = tempDirectory
            };

            writer.Write(messages, parameters);

            foreach (var file in directory.EnumerateFiles())
            {
                Console.Out.WriteLine("{0}", file.Name);
            }
        }
开发者ID:JohnEffo,项目名称:EasyNetQ,代码行数:31,代码来源:FileMessageWriterTests.cs

示例3: ImageDirectoryCapture

         /// <summary>
        /// Creates an instance of <see cref="ImageDirectoryCapture"/>.
        /// </summary>
        /// <param name="dirPath">The directory path.</param>
        /// <param name="searchPatterns">The image search patterns.</param>
        /// <param name="useNaturalSorting">Use natural sorting, otherwise raw image order is used.</param>
        /// <param name="recursive">If true searches the current directory and all subdirectories. Otherwise, only top directory is searched.</param>
        /// <exception cref="DirectoryNotFoundException">Directory can not be found.</exception>
        public ImageDirectoryCapture(string dirPath, string[] searchPatterns, bool useNaturalSorting = true, bool recursive = false)
        {
            FileReadFunction = ImageIO.LoadUnchanged;

            if (Directory.Exists(dirPath) == false)
                throw new DirectoryNotFoundException(String.Format("Dir: {0} cannot be found!", dirPath));

            DirectoryInfo directoryInfo = new DirectoryInfo(dirPath); 

            this.IsLiveStream = false;
            this.CanSeek = true;
            this.DirectoryInfo = directoryInfo;

            var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;

            if (useNaturalSorting)
            {
                this.FileInfos = directoryInfo.EnumerateFiles(searchPatterns, searchOption)
                                  .OrderBy(f => f.FullName, new NaturalSortComparer()) //in case of problems replace f.FullName with f.Name
                                  .ToArray();
            }
            else
            {
                this.FileInfos = directoryInfo.EnumerateFiles(searchPatterns, searchOption)
                                  .ToArray();
            }
        }
开发者ID:bestwpw,项目名称:dot-imaging,代码行数:35,代码来源:ImageDirectoryCapture.cs

示例4: Handle

        public override bool Handle(ProjectParser project)
        {
            var changed = false;

            var root = project.RootElement;
            var propertyGroups = root.PropertyGroups;
            foreach (var propertyGroup in propertyGroups)
            {
                //System.Diagnostics.Debug.WriteLine("PropertyGroup(" + propertyGroup.Condition + ")");

                var sccProperties = propertyGroup.AllChildren.Where(x => x is ProjectPropertyElement);
                foreach (ProjectPropertyElement sccProperty in sccProperties)
                {
                    if (!sccProperty.Name.StartsWith("Scc")) continue;

                    //System.Diagnostics.Debug.WriteLine(sccProperty);
                    propertyGroup.RemoveChild(sccProperty);
                    changed = true;
                }
            }

            var directoryInfo = new DirectoryInfo(project.DirectoryPath);
            var sccFiles = directoryInfo.EnumerateFiles("*.vspscc").Concat(directoryInfo.EnumerateFiles("*.vssscc"));
            foreach (var sccFile in sccFiles)
            {
                sccFile.MoveTo(sccFile.FullName+".bak");
            }
            return changed;
        }
开发者ID:Slesa,项目名称:Playground,代码行数:29,代码来源:RemoveSourceControlProcessor.cs

示例5: AddDirectory

        public void AddDirectory(string path)
        {
            DirectoryInfo dir = new DirectoryInfo(path);
            _directories.Add(dir);

            foreach (string fileType in FileTypeInfo.ImageFileTypes)
            {
                string mask = "*" + fileType;
                foreach (var f in dir.EnumerateFiles(mask))
                {
                    ImageFile image = new ImageFile(f);
                    _images.Add(image);
                    _filesByPath.Add(image.Path, image);
                }
            }

            foreach (string fileType in FileTypeInfo.VideoFileTypes)
            {
                string mask = "*" + fileType;
                foreach (var f in dir.EnumerateFiles(mask))
                {
                    VideoFile video = new VideoFile(f);
                    _videos.Add(video);
                    _filesByPath.Add(video.Path, video);
                }
            }
        }
开发者ID:JadeHub,项目名称:Pics,代码行数:27,代码来源:LibraryFileList.cs

示例6: 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

示例7: LoadContent

    /// <summary>
    /// Loads graphics content
    /// </summary>
    public void LoadContent()
    {
      // Load textures
      DirectoryInfo gfxDirectory = new DirectoryInfo("gfx");
      foreach (FileInfo file in gfxDirectory.EnumerateFiles("tex_*.png", SearchOption.AllDirectories))
      {
        int start = file.FullName.LastIndexOf("\\gfx\\");
        string id = file.FullName.Substring(start + 5, file.FullName.Length - start - 4 - 5);
        id = id.Substring(4);
        texDict.Add(id, LoadTexture(file.FullName));
      }
      
      texPoint = GetTexture("point");

      // Load files
      foreach (FileInfo file in gfxDirectory.EnumerateFiles("*.fnt", SearchOption.AllDirectories))
      {
        fntDict.Add(file.Name.Substring(0, file.Name.Length - 4), LoadFont(file.FullName));
      }

      // Load skins(styles)
      foreach (FileInfo file in gfxDirectory.EnumerateFiles("*.skn", SearchOption.AllDirectories))
      {
        guiTexDict.Add(file.Name.Substring(0, file.Name.Length - 4), LoadGuiTexture(file.FullName));
      }
    }
开发者ID:arcticnw,项目名称:Wildmen,代码行数:29,代码来源:UI_Graphics.cs

示例8: 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

示例9: With

        public IISExpressConfigBuilder With(string pathToProject)
        {
            var projectDirectory = new DirectoryInfo(pathToProject);
            var projectFile = projectDirectory.EnumerateFiles("*.csproj").SingleOrDefault() ??
                              projectDirectory.EnumerateFiles("*.vbproj").SingleOrDefault();

            if (projectFile == null)
            {
                throw new FileNotFoundException("No C# or VB.NET projects were found in " + projectDirectory.FullName);
            }

            _action.ProjectPath = projectFile.FullName;
            return this;
        }
开发者ID:poprhythm,项目名称:SpecsFor,代码行数:14,代码来源:IISExpressConfigBuilder.cs

示例10: GetFiles

        public override IEnumerable<DataFile> GetFiles(string searchPattern = null)
        {
            var directory = new DirectoryInfo(PhysicalPath);
            if (!directory.Exists)
            {
                yield break;
            }

            var files = searchPattern == null ? directory.EnumerateFiles() : directory.EnumerateFiles(searchPattern, SearchOption.TopDirectoryOnly);
            foreach (var file in files)
            {
                yield return new DiskDataFile(UrlUtility.Combine(VirtualPath, file.Name), DefaultFileFormat);
            }
        }
开发者ID:Kooboo,项目名称:Ecommerce,代码行数:14,代码来源:DiskDataFolder.cs

示例11: ScanDirectoriesRecursive

		private void ScanDirectoriesRecursive(string folder)
		{
			var dir = new DirectoryInfo(folder);

			// Ignore files that appear to be opened with excel.
			var xlsFileInfo = dir.EnumerateFiles().Where(f => f.Extension == ".xls" && !f.Name.StartsWith("~"));
			var xlsxFileInfo = dir.EnumerateFiles().Where(f => f.Extension == ".xlsx" && !f.Name.StartsWith("~"));
			var zipFileInfo = dir.EnumerateFiles().Where(f => f.Extension == ".zip");

			xlsFiles.AddRange(xlsFileInfo);
			xlsxFiles.AddRange(xlsxFileInfo);
			zipFiles.AddRange(zipFileInfo);

			dir.GetDirectories().ToList().ForEach(d => ScanDirectoriesRecursive(d.FullName));
		}
开发者ID:gkochanowsky,项目名称:Read_XLSX,代码行数:15,代码来源:DataDump.cs

示例12: Main

		private static void Main(string[] args) {
			var outDirInfo = new DirectoryInfo(@"C:\coverage");
			var inputDirInfo =
					new DirectoryInfo(
							@"C:\Users\exKAZUu\Projects\UnitMaster\fixture\Java\MinForUnitMaster\src\main"
							//@"..\..\..\fixture\project\input\GetMid"
							);
			var excludeInDirInfo =
					new DirectoryInfo(@"..\..\..\fixture\project\input\GetMid\test");

			var instrumenter = new SampleInstrumenter(outDirInfo, inputDirInfo);
			var profile = LanguageSupports.GetCoverageModeByClassName("Java");
			var regexes =
					profile.FilePatterns.Select(
							pattern => new Regex(pattern.Replace("*", ".*").Replace("?", ".")));

			outDirInfo.Create();
			var fileInfos = inputDirInfo.EnumerateFiles("*", SearchOption.AllDirectories);
			foreach (var fileInfo in fileInfos) {
				if (regexes.Any(regex => regex.IsMatch(fileInfo.FullName))) {
					if (!fileInfo.FullName.StartsWith(excludeInDirInfo.FullName)) {
						instrumenter.WriteInstrumentedProductionCode(profile, fileInfo);
					} else {
						instrumenter.WriteInstrumentedTestCode(profile, fileInfo);
					}
				} else {
					instrumenter.CopyFile(fileInfo);
				}
			}
			profile.CopyLibraries(instrumenter.OutDirInfo, RecordingMode.TextFile);
		}
开发者ID:audioglider,项目名称:OpenCodeCoverageFramework,代码行数:31,代码来源:Program.cs

示例13: CanCheckoutProject

        public void CanCheckoutProject()
        {
            var executableDirectory = DirectoryHelper.ExecutingDirectory();

            var outputDirectory = Path.Combine(executableDirectory.FullName, "SubversionOutput");

            var tasks = TaskHelper.Start()
            .Subversion("http://openjpeg.googlecode.com/svn/trunk/", outputDirectory)
            .Finalize();

            var command = new KissCommand("build", tasks);

            var project = new KissProject("TestProject", "UI", command);

            using (var projectService = TestHelper.GetService())
            {
                projectService.RegisterProject(project);

                ProjectHelper.Run(project, command, projectService);

                var output = new DirectoryInfo(outputDirectory);

                Assert.IsTrue(output.EnumerateFiles().Any());
            }
        }
开发者ID:jgreene,项目名称:KissCI,代码行数:25,代码来源:SubversionTests.cs

示例14: FindAllFoldersAndFiles

        private static void FindAllFoldersAndFiles(DirectoryInfo di, Folder root)
        {
            try
            {
                var files = di.EnumerateFiles();
                foreach (var file in files)
                {
                    var currentFile = new File(file.Name, file.Length);
                    root.Files.Add(currentFile);
                }

                var folders = di.EnumerateDirectories();
                foreach (var folder in folders)
                {
                    var currentFolder = new Folder(folder.Name);
                    root.ChildFolders.Add(currentFolder);

                    FindAllFoldersAndFiles(folder, currentFolder);
                }
            }
            catch (UnauthorizedAccessException e)
            {
                Console.WriteLine(e.Message);
            }
        }
开发者ID:niki-funky,项目名称:Telerik_Academy,代码行数:25,代码来源:FileStructure.cs

示例15: Form1_Load

        private void Form1_Load(object sender, EventArgs e)
        {
            poolList = new List<PoolItem>();
            miners = new List<Miner>();
            readList();

            DirectoryInfo dir = new DirectoryInfo(Application.StartupPath);

            foreach (FileInfo file in dir.EnumerateFiles("*_log.txt")) {
                file.Delete();
            }

            FileSystemWatcher watcher = new FileSystemWatcher();
            watcher.Path = Application.StartupPath;
            watcher.EnableRaisingEvents = true;
            watcher.Filter = "*_log.txt";
            watcher.Created += new FileSystemEventHandler(newLogFound);

            hashChart.Series[0].YAxisType = AxisType.Primary;
            hashChart.Series[0].YValueType = ChartValueType.Single;
            hashChart.Series[0].IsXValueIndexed = false;

            hashChart.ResetAutoValues();
            hashChart.ChartAreas[0].AxisY.Maximum = 1;
            hashChart.ChartAreas[0].AxisY.Minimum = 0;
            hashChart.ChartAreas[0].AxisX.Enabled = AxisEnabled.False;
            hashChart.ChartAreas[0].AxisY.IntervalAutoMode = IntervalAutoMode.FixedCount;
        }
开发者ID:curly-brace,项目名称:Claymore-CPU-Miner-GUI,代码行数:28,代码来源:Form1.cs


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