當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。