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


C# DirectoryInfo.GetFolders方法代码示例

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


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

示例1: ReadIncludePatternFromFile

 public void ReadIncludePatternFromFile()
 {
     SaveConfiguration();
     TaskConfiguration actualTaskConfiguration = Extensions.Deserialize(new TaskConfiguration(), ConfigurationFile, DefaultNamespace);
     ArchiveTask task = null;
     foreach (ArchiveTask archiveTask in actualTaskConfiguration.ArchiveTasks)
     {
         if (archiveTask.RegExpressionInclude != null)
         {
             task = archiveTask;
             break;
         }
     }
     DirectoryInfo directoryInfo = new DirectoryInfo(@"..\..\TestFiles\Archive\source");
     List<DirectoryInfo> folders = directoryInfo.GetFolders(task);
     const int expectedValue = 1;
     Assert.AreEqual(expectedValue, folders.Count);
 }
开发者ID:trippleflux,项目名称:jezatools,代码行数:18,代码来源:Configuration.cs

示例2: ExecuteArchiveTasks

 private void ExecuteArchiveTasks()
 {
     foreach (ArchiveTask task in taskConfiguration.ArchiveTasks)
     {
         if (task.ArchiveStatus == ArchiveStatus.Enabled)
         {
             Log.Debug("Starting with task: ['{0}']", task.ToString());
             DirectoryInfo sourceFolder;
             try
             {
                 sourceFolder = new DirectoryInfo(task.Source);
             }
             catch (Exception exception)
             {
                 Log.Debug(exception.StackTrace);
                 throw;
             }
             List<DirectoryInfo> sourceFolders = sourceFolder.GetFolders(task);
             if (task.Action.MinFolderAction > sourceFolders.Count)
             {
                 Log.Debug("Skiping task because of MinFolderAction > ActualFodlersCount! '{0}' :: {1}", task.Action.MinFolderAction, sourceFolders.Count);
                 continue;
             }
             switch (task.Action.Id)
             {
                 case ArchiveActionAttribute.DateOlder:
                 {
                     foreach (DirectoryInfo directoryInfo in sourceFolders)
                     {
                         var dateTime = new DateTime(DateTime.UtcNow.Ticks);
                         DateTime creationTimeUtc = directoryInfo.CreationTimeUtc;
                         TimeSpan timeSpan = dateTime - creationTimeUtc;
                         if ((UInt64) timeSpan.Days > task.Action.Value)
                         {
                             ExecuteArchiveTask(task, directoryInfo);
                         }
                     }
                     break;
                 }
                 case ArchiveActionAttribute.TotalFolderCount:
                 {
                     if ((UInt64) sourceFolders.Count > task.Action.Value)
                     {
                         ExecuteArchiveTask(task, sourceFolders);
                     }
                     break;
                 }
                 case ArchiveActionAttribute.TotalFreeSpace:
                 {
                     ManageDiskSpace(task, sourceFolders);
                     break;
                 }
                 case ArchiveActionAttribute.TotalUsedSpace:
                 {
                     ManageDiskSpace(task, sourceFolders);
                     break;
                 }
                 case ArchiveActionAttribute.TotalFolderUsedSpace:
                 {
                     UInt64 totalFolderSize = sourceFolders.Aggregate<DirectoryInfo, ulong>(0, (current,
                                                                                                directoryInfo) => current + directoryInfo.GetFolderSize());
                     if (totalFolderSize > task.Action.Value)
                     {
                         ExecuteArchiveTask(task, sourceFolders);
                     }
                     break;
                 }
                 default:
                 {
                     throw new NotSupportedException();
                 }
             }
         }
         else
         {
             Log.Debug("Task is disabled! ['{0}']", task.ToString());
         }
     }
 }
开发者ID:trippleflux,项目名称:jezatools,代码行数:79,代码来源:ConsoleAppTasks.cs

示例3: NumberOfFoldersInSource

 public void NumberOfFoldersInSource()
 {
     DirectoryInfo directoryInfo = new DirectoryInfo(@"..\..\TestFiles\Archive\source");
     archiveTask.RegExpressionInclude = null;
     archiveTask.RegExpressionExclude = @"\b(\.|[Ff]|[Ss])\S*";
     List<DirectoryInfo> folders = directoryInfo.GetFolders(archiveTask);
     const int expectedValue = 4;
     Assert.AreEqual(expectedValue, folders.Count);
 }
开发者ID:trippleflux,项目名称:jezatools,代码行数:9,代码来源:Folders.cs


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