本文整理汇总了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);
}
示例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());
}
}
}
示例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);
}