C# DirectoryInfo.GetFiles的代码示例
通过代码示例来学习C# DirectoryInfo.GetFiles方法
通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。
DirectoryInfo.GetFiles是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的DirectoryInfo.GetFiles() 已经帮大家高亮显示了,大家可以重点学习DirectoryInfo.GetFiles() 方法的写法,从而快速掌握该方法的应用。
DirectoryInfo.GetFiles的代码示例1 - DoParallelActions()
using System.IO; #endregion #region Public Methods ///
/// For each of the documents in the folder 'Parallel\Resources\', /// Replace the string "Apple" with the string "Potato" and replace the "Apple" image by a "Potato" image. /// Do this in Parrallel accross many CPU cores. /// public static void DoParallelActions() { Console.WriteLine( "\tDoParallelActions()" ); // Get the docx files from the Resources directory. var inputDir = new DirectoryInfo( ParallelSample.ParallelSampleResourcesDirectory ); var inputFiles = inputDir.GetFiles( "*.docx" ); // Loop through each document and do actions on them. Parallel.ForEach( inputFiles, f => ParallelSample.Action( f ) ); }
开发者ID:xceedsoftware,项目名称:DocX,代码行数:22,代码来源:ParallelSample.cs
在DoParallelActions()方法中,DirectoryInfo的代码示例类中的GetFiles的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
DirectoryInfo.GetFiles的代码示例2 - ServiceLogContainsUpgradeMessaging()
using System.IO; private bool ServiceLogContainsUpgradeMessaging() { // This test checks for the upgrade timer start message in the Service log // file. GVFS.Service should schedule the timer as it starts. string expectedTimerMessage = "Checking for product upgrades. (Start)"; string serviceLogFolder = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "GVFS", GVFSServiceProcess.TestServiceName, "Logs"); DirectoryInfo logsDirectory = new DirectoryInfo(serviceLogFolder); FileInfo logFile = logsDirectory.GetFiles() .OrderByDescending(f => f.LastWriteTime) .FirstOrDefault(); if (logFile != null) { using (StreamReader fileStream = new StreamReader(File.Open(logFile.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))) { string nextLine = null; while ((nextLine = fileStream.ReadLine()) != null) { if (nextLine.Contains(expectedTimerMessage)) { return true; } } } } return false; }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:34,代码来源:GVFSUpgradeReminderTests.cs
在ServiceLogContainsUpgradeMessaging()方法中,DirectoryInfo的代码示例类中的GetFiles的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
DirectoryInfo.GetFiles的代码示例3 - FindNewestFileInFolder()
using System.IO; private static string FindNewestFileInFolder(string folderName, string logFileType) { string logFilePattern = GetLogFilePatternForType(logFileType); DirectoryInfo logDirectory = new DirectoryInfo(folderName); if (!logDirectory.Exists) { return null; } FileInfo[] files = logDirectory.GetFiles(logFilePattern ?? "*"); if (files.Length == 0) { return null; } return files .OrderByDescending(fileInfo => fileInfo.CreationTime) .First() .FullName; }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:24,代码来源:LogVerb.cs
在FindNewestFileInFolder()方法中,DirectoryInfo的代码示例类中的GetFiles的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
DirectoryInfo.GetFiles的代码示例4 - DeleteDirectory()
using System.IO; public virtual void DeleteDirectory(string path, bool recursive = true, bool ignoreDirectoryDeleteExceptions = false) { if (!Directory.Exists(path)) { return; } DirectoryInfo directory = new DirectoryInfo(path); if (recursive) { foreach (FileInfo file in directory.GetFiles()) { file.Attributes = FileAttributes.Normal; file.Delete(); } foreach (DirectoryInfo subDirectory in directory.GetDirectories()) { this.DeleteDirectory(subDirectory.FullName, recursive, ignoreDirectoryDeleteExceptions); } } try { directory.Delete(); } catch (Exception) { if (!ignoreDirectoryDeleteExceptions) { throw; } } }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:37,代码来源:PhysicalFileSystem.cs
在DeleteDirectory()方法中,DirectoryInfo的代码示例类中的GetFiles的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
DirectoryInfo.GetFiles的代码示例5 - DeleteDirectory()
using System.IO; public override string DeleteDirectory(string path) { DirectoryInfo directory = new DirectoryInfo(path); foreach (FileInfo file in directory.GetFiles()) { file.Attributes = FileAttributes.Normal; RetryOnException(() => file.Delete()); } foreach (DirectoryInfo subDirectory in directory.GetDirectories()) { this.DeleteDirectory(subDirectory.FullName); } RetryOnException(() => directory.Delete()); return string.Empty; }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:21,代码来源:SystemIORunner.cs
在DeleteDirectory()方法中,DirectoryInfo的代码示例类中的GetFiles的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
DirectoryInfo.GetFiles的代码示例6 - Install()
using System.IO; static void Install() { Console.WriteLine("Installing..."); foreach (string dir in Directory.GetDirectories("master/")) { SetAccessRule(folderDir); SetAccessRule(dir); string dirName = new DirectoryInfo(dir).Name; string destDir = Path.Combine(folderDir, dirName + @"\"); //Skip hash directory if (dirName.Equals("Hashes", StringComparison.CurrentCultureIgnoreCase)) continue; if (Directory.Exists(destDir)) { Directory.Delete(destDir, true); } if (Directory.Exists(destDir)) Directory.Delete(destDir, true); Directory.Move(dir, destDir); } foreach (string file in Directory.GetFiles("master/")) { if (file.Contains("Updater.exe") || file.Contains("Updater.exe.config") || file.Contains("Updater.pdb") || file.Contains("Octokit.dll")) continue; SetAccessRule(file); SetAccessRule(folderDir); string destFile = Path.Combine(folderDir, Path.GetFileName(file)); if (File.Exists(destFile)) File.Delete(destFile); File.Move(file, destFile); } }
开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:42,代码来源:Program.cs
在Install()方法中,DirectoryInfo的代码示例类中的GetFiles的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
DirectoryInfo.GetFiles的代码示例7 - GetActualEntries()
using System.IO; ///
/// Gets a public static FileEntryGraph GetActualEntries(string outputDir, string forFileName) { var actualEntries = new FileEntryGraph(forFileName); var dir = new DirectoryInfo(outputDir); var dirsToProcess = new Stackrepresenting the files in the specified outputDir (where an MSI was extracted). /// (); dirsToProcess.Push(dir); while (dirsToProcess.Count > 0) { dir = dirsToProcess.Pop(); foreach (var file in dir.GetFiles()) { actualEntries.Add(new FileEntry(file, outputDir)); } foreach (var subDir in dir.GetDirectories()) { dirsToProcess.Push(subDir); } } return actualEntries; }
开发者ID:activescott,项目名称:lessmsi,代码行数:25,代码来源:FileEntryGraph.cs
在GetActualEntries()方法中,DirectoryInfo的代码示例类中的GetFiles的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
DirectoryInfo.GetFiles的代码示例8 - Indexer()
using System.IO; static void Indexer() { string indexerFile = ""; try { Guid IPropertyStoreGuid = new Guid("886D8EEB-8CF2-4446-8D02-CDBA1DBDCF99"); DirectoryInfo di = new DirectoryInfo(targetDirectory); bool done = false; while (!done) { foreach (FileInfo file in di.GetFiles()) { indexerFile = file.Name; // To simulate indexer, open handler directly to get fine-grained control over flags //HResult hr = (HResult)SHGetPropertyStoreFromParsingName(file.FullName, IntPtr.Zero, // GETPROPERTYSTOREFLAGS.GPS_DEFAULT, ref IPropertySto on '{indexerFile}'reGuid, out IPropertyStore ps); var ps = new IPropertyHandler(); try { HResult hr = ps.Initialize(file.FullName, (uint)(StgmConstants.STGM_READ | StgmConstants.STGM_SHARE_DENY_NONE)); if (hr == HResult.Ok) { hr = ps.GetCount(out uint propertyCount); if (hr == HResult.Ok) { for (uint index = 0; index < propertyCount; index++) { PropVariant val = new PropVariant(); hr = ps.GetAt(index, out PropertyKey key); if (hr == HResult.Ok) { hr = ps.GetValue(key, val); if (hr == HResult.Ok) LogLine(3, $"Indexer read {val}"); else throw new Exception($"GetValue failed with 0x{hr:X}"); } else throw new Exception($"GetAt failed with 0x{hr:X}"); } } else if ((uint)hr == 0x80030021) { LogLine(2, $"GetCount for {indexerFile} failed with STG_E_LOCKVIOLATION"); IncrementIndexerFail(); } else throw new Exception($"GetCount failed with 0x{hr:X}"); done = IncrementIndexer(); if (done) break; } else if ((uint)hr == 0x80030021) { LogLine(2, $"Open for {indexerFile} failed with STG_E_LOCKVIOLATION"); IncrementIndexerFail(); } //else // throw new Exception($"Open failed with 0x{hr:X}"); else { // Indexer can tolerate some failures, but not too many LogLine(1, $"Indexer Open failed on '{indexerFile}' with 0x{hr:X}"); IncrementIndexerFail(); } } finally { Marshal.ReleaseComObject(ps); // optional GC preempt } } } } catch (Exception ex) { LogLine(1, $"Indexer terminated on '{indexerFile}': {ex}"); IncrementIndexerTerminated(); } }
开发者ID:Dijji,项目名称:FileMeta,代码行数:86,代码来源:Program.cs
在Indexer()方法中,DirectoryInfo的代码示例类中的GetFiles的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
本文中的DirectoryInfo.GetFiles方法示例由csref.cn整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。