本文整理汇总了C#中IDirectory.EnumerateFiles方法的典型用法代码示例。如果您正苦于以下问题:C# IDirectory.EnumerateFiles方法的具体用法?C# IDirectory.EnumerateFiles怎么用?C# IDirectory.EnumerateFiles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDirectory
的用法示例。
在下文中一共展示了IDirectory.EnumerateFiles方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MapPropertiesRecursive
private static void MapPropertiesRecursive(JsonObject jObject, IDirectory directory)
{
foreach (var file in directory.EnumerateFiles())
{
var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file.Name);
if (fileNameWithoutExtension == null || fileNameWithoutExtension == IdPropertyName)
continue;
if (ReservedPropertyNames.Contains(fileNameWithoutExtension))
throw new DesignDocumentAssemblerException("File name {0} is reserved.", file);
if (jObject.ContainsKey(fileNameWithoutExtension))
throw CreateClashingFilesException(directory, fileNameWithoutExtension);
jObject[fileNameWithoutExtension] = ReadFile(file);
}
foreach (var subDirectory in directory.EnumerateDirectories())
{
var subDirectoryName = subDirectory.Name;
if (ReservedPropertyNames.Contains(subDirectoryName))
throw new DesignDocumentAssemblerException("Directory name {0} is reserved.", subDirectoryName);
if (jObject.ContainsKey(subDirectoryName))
throw CreateClashingFilesException(directory, subDirectoryName);
var subObject = new JsonObject();
jObject[subDirectoryName] = subObject;
MapPropertiesRecursive(subObject, subDirectory);
}
}
示例2: AssertDirectoryWithFile
private static void AssertDirectoryWithFile(IDirectory directory)
{
Assert.NotNull(directory);
var files = directory.EnumerateFiles().ToArray();
Assert.Equal(1, files.Length);
Assert.Equal("test.txt", files[0].Name);
}
示例3: CreateClashingFilesException
CreateClashingFilesException(IDirectory directory, string clashingName)
{
var clushingFileNames = directory
.EnumerateFiles()
.Where(f => Path.GetFileNameWithoutExtension(f.Name) == clashingName)
.Select(f => f.Name);
var clushingSubDirectoryNames = directory
.EnumerateDirectories()
.Where(d => d.Name == clashingName)
.Select(d => d.Name);
var clashingDirectoriesAndFiles =
clushingFileNames.Union(clushingSubDirectoryNames).ToArray();
return new DesignDocumentAssemblerException(
"Files and subdirectories with same name and different extensions detected: {0}",
string.Join(", ", clashingDirectoriesAndFiles));
}
示例4: GetIdFile
private static IFile GetIdFile(IDirectory subDirectory)
{
return subDirectory
.EnumerateFiles()
.FirstOrDefault(n => Path.GetFileNameWithoutExtension(n.Name) == IdPropertyName);
}