本文整理汇总了C#中System.IO.DirectoryInfo.EnumerateFileSystemInfos方法的典型用法代码示例。如果您正苦于以下问题:C# DirectoryInfo.EnumerateFileSystemInfos方法的具体用法?C# DirectoryInfo.EnumerateFileSystemInfos怎么用?C# DirectoryInfo.EnumerateFileSystemInfos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.DirectoryInfo
的用法示例。
在下文中一共展示了DirectoryInfo.EnumerateFileSystemInfos方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestCoreCLRIssue
private bool TestCoreCLRIssue()
{
string root = null;
try
{
root = Path.GetTempFileName();
File.Delete(root);
Directory.CreateDirectory(root);
var testDir = new DirectoryInfo(root);
var betaDir = Path.Combine(root, "beta");
Directory.CreateDirectory(betaDir);
var beta = testDir.EnumerateFileSystemInfos("beta", SearchOption.TopDirectoryOnly).First() as DirectoryInfo;
return !beta.Exists;
}
finally
{
if (root != null && Directory.Exists(root))
{
Directory.Delete(root, true);
}
}
}
示例2: CreateDirectoryGetResponse
protected override Task<HttpResponseMessage> CreateDirectoryGetResponse(DirectoryInfo info, string localFilePath)
{
HttpResponseMessage response = Request.CreateResponse();
using (var zip = new ZipFile())
{
foreach (FileSystemInfo fileSysInfo in info.EnumerateFileSystemInfos())
{
bool isDirectory = (fileSysInfo.Attributes & FileAttributes.Directory) != 0;
if (isDirectory)
{
zip.AddDirectory(fileSysInfo.FullName, fileSysInfo.Name);
}
else
{
// Add it at the root of the zip
zip.AddFile(fileSysInfo.FullName, "/");
}
}
using (var ms = new MemoryStream())
{
zip.Save(ms);
response.Content = ms.AsContent();
}
}
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/zip");
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
// Name the zip after the folder. e.g. "c:\foo\bar\" --> "bar"
response.Content.Headers.ContentDisposition.FileName = Path.GetFileName(Path.GetDirectoryName(localFilePath)) + ".zip";
return Task.FromResult(response);
}
示例3: GetTree
public INode GetTree(string rootPath)
{
var directoryInfo = new DirectoryInfo(rootPath);
if (directoryInfo.Attributes != FileAttributes.Directory)
{
var file = new FileInfo(rootPath);
return new Node
{
Id = file.FullName,
Name = file.Name,
NodeType = NodeType.File,
Children = new INode[0],
};
}
var result = new Node
{
Id = directoryInfo.FullName,
Name = directoryInfo.Name,
NodeType = NodeType.Folder
};
result.Children = directoryInfo.EnumerateFileSystemInfos().Select(fileSystemInfo => new Node { Id = fileSystemInfo.FullName, Name = fileSystemInfo.Name, Children = new INode[0] }).ToList();
return result;
}
示例4: CleanDirectoryPath
private bool CleanDirectoryPath(CmdletProgress bar, DateTime dtNow, TimeSpan age, DirectoryInfo currentDirecotry, string relativePath)
{
var empty = true;
foreach (var fsi in currentDirecotry.EnumerateFileSystemInfos())
{
var currentRelativePath = Path.Combine(relativePath, fsi.Name);
var di = fsi as DirectoryInfo;
var fi = fsi as FileInfo;
if (di != null)
{
if (CleanDirectoryPath(bar, dtNow, age, di, currentRelativePath))
{
directoriesDeleted++;
empty = DeleteSafe(bar, di.Delete, currentRelativePath);
}
else
empty = false;
}
else if (fi != null)
{
if (IsOutAged(dtNow, fi.LastAccessTime, age) || IsOutAged(dtNow, fi.LastWriteTime, age) || IsOutAged(dtNow, fi.LastAccessTime, age))
{
bytesDeleted += fi.Length;
filesDeleted++;
if (!DeleteSafe(bar, fi.Delete, currentRelativePath))
empty = false;
}
else
empty = false;
}
}
return empty;
}
示例5: ZipDirectory
public static void ZipDirectory(string dir)
{
string zipfile_name = dir + ".zip";
if (File.Exists(zipfile_name))
{
return;
}
using (var zip = new ZipFile(Encoding.GetEncoding("shift_jis")))
{
zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;
var di = new DirectoryInfo(dir);
foreach (var i in di.EnumerateFileSystemInfos())
{
if (FileAttributes.Directory == (i.Attributes & FileAttributes.Directory))
{
zip.AddDirectory(i.FullName, i.Name);
}
else if (FileAttributes.Hidden != (i.Attributes & FileAttributes.Hidden))
{
zip.AddFile(i.FullName, "");
}
}
zip.Save(zipfile_name);
}
}
示例6: CreateDirectoryGetResponse
protected override Task<HttpResponseMessage> CreateDirectoryGetResponse(DirectoryInfo info, string localFilePath)
{
HttpResponseMessage response = Request.CreateResponse();
using (var ms = new MemoryStream())
{
using (var zip = new ZipArchive(ms, ZipArchiveMode.Create, leaveOpen: true))
{
foreach (FileSystemInfo fileSysInfo in info.EnumerateFileSystemInfos())
{
DirectoryInfo directoryInfo = fileSysInfo as DirectoryInfo;
if (directoryInfo != null)
{
zip.AddDirectory(new DirectoryInfoWrapper(directoryInfo), fileSysInfo.Name);
}
else
{
// Add it at the root of the zip
zip.AddFile(fileSysInfo.FullName, String.Empty);
}
}
}
response.Content = ms.AsContent();
}
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/zip");
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
// Name the zip after the folder. e.g. "c:\foo\bar\" --> "bar"
response.Content.Headers.ContentDisposition.FileName = Path.GetFileName(Path.GetDirectoryName(localFilePath)) + ".zip";
return Task.FromResult(response);
}
示例7: AddDirectory
public static void AddDirectory(this ZipArchive archive, string sourceDir)
{
DirectoryInfo directoryInfo = new DirectoryInfo(sourceDir);
sourceDir = directoryInfo.FullName;
foreach (FileSystemInfo entry in directoryInfo.EnumerateFileSystemInfos("*", SearchOption.AllDirectories))
{
string relativePath = entry.FullName.Substring(sourceDir.Length, entry.FullName.Length - sourceDir.Length);
relativePath = relativePath.TrimStart(new char[]
{
Path.DirectorySeparatorChar,
Path.AltDirectorySeparatorChar
});
if (entry is FileInfo)
{
archive.AddFile(entry.FullName, relativePath);
}
else
{
DirectoryInfo subDirInfo = entry as DirectoryInfo;
if (subDirInfo != null && !subDirInfo.EnumerateFileSystemInfos().Any())
{
archive.CreateEntry(relativePath + Path.DirectorySeparatorChar);
}
}
}
}
示例8: ImplFindFiles
internal override IEnumerable<FileSystemEntry> ImplFindFiles(String Path)
{
String CachedRealPath = RealPath(Path);
DirectoryInfo DirectoryInfo = new DirectoryInfo(CachedRealPath);
foreach (var Item in DirectoryInfo.EnumerateFileSystemInfos())
{
if (!Item.FullName.StartsWith(CachedRealPath))
{
throw(new Exception("Unexpected FullName"));
}
if (Item.Attributes.HasFlag(FileAttributes.Hidden))
{
continue;
}
var FileSystemEntry = new LocalFileSystemEntry(this, Path + "/" + Item.Name, Item);
//FileSystemEntry.Size = File.get
//Item.Attributes == FileAttributes.
//
//FileSystemEntry.Time = Item.
yield return FileSystemEntry;
}
}
示例9: MightContainSolution
public static bool MightContainSolution(this ISimpleRepositoryModel repository)
{
var dir = new DirectoryInfo(repository.LocalPath);
return dir.EnumerateFileSystemInfos("*", SearchOption.TopDirectoryOnly)
.Any(x => ((x.Attributes.HasFlag(FileAttributes.Directory) || x.Attributes.HasFlag(FileAttributes.Normal)) &&
!x.Name.StartsWith(".", StringComparison.Ordinal) && !x.Name.StartsWith("readme", StringComparison.OrdinalIgnoreCase)));
}
示例10: GetDpxAdjGraph
public static AsmAdjancyGraph GetDpxAdjGraph(string binDir)
{
try
{
if (string.IsNullOrWhiteSpace(binDir) || !Directory.Exists(binDir))
{
var asmAdjGraph = new AsmAdjancyGraph
{
Msg = $"The bin directory {binDir} is null or does not exist.",
St = MetadataTokenStatus.Error
};
return asmAdjGraph;
}
//get all the dll files in the dir
var di = new DirectoryInfo(binDir);
var dllsFullNames =
di.EnumerateFileSystemInfos("*.dll", SearchOption.TopDirectoryOnly).Select(x => x.FullName).ToArray();
if (!dllsFullNames.Any())
{
var asmAdjGraph = new AsmAdjancyGraph
{
Msg = $"The directory {binDir} does not contain any files with a .dll extension.",
St = MetadataTokenStatus.Error
};
return asmAdjGraph;
}
//get all the assembly names of direct files and each of thier ref's
var asmIndxBuffer = new List<Tuple<RankedMetadataTokenAsm, RankedMetadataTokenAsm[]>>();
foreach (var dll in dllsFullNames)
{
var asmName = AssemblyName.GetAssemblyName(dll);
if (asmName == null)
continue;
var asm = Asm.NfLoadFrom(dll);
var refs = asm.GetReferencedAssemblies().ToArray();
var mdta = new RankedMetadataTokenAsm
{
AssemblyName = asm.GetName().FullName,
IndexId = -1,
DllFullName = dll,
HasPdb = File.Exists(Path.ChangeExtension(dll, "pdb"))
};
asmIndxBuffer.Add(new Tuple<RankedMetadataTokenAsm, RankedMetadataTokenAsm[]>(mdta,
refs.Select(x => new RankedMetadataTokenAsm { AssemblyName = x.FullName, IndexId = -2}).ToArray()));
}
return GetDpxAdjGraph(asmIndxBuffer);
}
catch (Exception ex)
{
return new AsmAdjancyGraph {Msg = ex.Message, St = MetadataTokenStatus.Error};
}
}
示例11: Run_DirectoryInfo_Enumerate
private static void Run_DirectoryInfo_Enumerate() {
System.Console.Write(" -- Run_DirectoryInfo_Enumerate ");
var stopwatch = Stopwatch.StartNew();
var baseDir = new DirectoryInfo(_baseDir);
var entries = baseDir.EnumerateFileSystemInfos("*", SearchOption.AllDirectories);
var count = entries.Count();
stopwatch.Stop();
System.Console.Write(" -- Count: {0} -- Time {1} = {2}/sec", count, stopwatch.Elapsed, 1000.0 * count / stopwatch.ElapsedMilliseconds);
}
示例12: ScanDirectory
void ScanDirectory(string directory)
{
DirectoryInfo directoryInfo = new DirectoryInfo (directory);
foreach (FileSystemInfo info in directoryInfo.EnumerateFileSystemInfos ()) {
queue.Enqueue (info);
if ((info.Attributes & FileAttributes.Directory) != 0) {
ScanDirectory (info.FullName);
}
}
queue.Enqueue (null);
}
示例13: DeleteEmptyFolders
private void DeleteEmptyFolders(DirectoryInfo directoryInfo)
{
foreach (var directory in directoryInfo.EnumerateDirectories())
{
DeleteEmptyFolders(directory);
}
if (!directoryInfo.EnumerateFileSystemInfos().Any())
{
directoryInfo.Delete();
}
}
示例14: CreateFromDirectoryHelper
private static Task CreateFromDirectoryHelper(string sourcePath, string archiveFilePath, IProgress<float> progress, CancellationToken cancelToken)
{
sourcePath = Path.GetFullPath(sourcePath);
archiveFilePath = Path.GetFullPath(archiveFilePath);
var folderSeparators = new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar };
return Task.Run(() =>
{
using (var zipArchive = ZipFile.Open(archiveFilePath, ZipArchiveMode.Create, Encoding.UTF8))
{
var directoryInfo = new DirectoryInfo(sourcePath);
// this code results in two run-throughs of the source folder, but
// because of windows file system caching, the second run-through below,
// will be much faster than the first
var totalBytes = directoryInfo
.EnumerateFiles("*", SearchOption.AllDirectories)
.Sum(fi => fi.Length);
var currentBytes = 0L;
cancelToken.ThrowIfCancellationRequested();
foreach (var info in directoryInfo.EnumerateFileSystemInfos("*", SearchOption.AllDirectories))
{
cancelToken.ThrowIfCancellationRequested();
int length = info.FullName.Length - sourcePath.Length;
var entryName = info.FullName.Substring(sourcePath.Length, length).TrimStart(folderSeparators);
if (info is FileInfo)
{
var sourceInfo = (FileInfo)info;
using (var source = sourceInfo.OpenRead())
{
var entry = zipArchive.CreateEntry(entryName);
entry.LastWriteTime = sourceInfo.GetLastWriteTime();
using (var destination = entry.Open())
{
currentBytes += StreamCopyHelper(source, destination, progress, totalBytes, currentBytes, cancelToken);
}
}
}
else if (info is DirectoryInfo)
{
if (IsFolderEmpty(info.FullName))
{
// create entry for empty folder
zipArchive.CreateEntry(string.Concat(entryName, Path.DirectorySeparatorChar));
}
}
}
}
});
}
示例15: Execute
public void Execute(ProjectConfiguration configuration, string selectedProject)
{
DirectoryInfo projectDirectory = new DirectoryInfo(configuration.RootPath);
List<FileSystemInfo> projectFiles = projectDirectory
.EnumerateFileSystemInfos("*.csproj", SearchOption.AllDirectories)
.ToList();
var targetProjects = configuration.ResolveAssemblies(selectedProject);
if (_checkOnlyDependencies)
{
var projectSetup = new ProjectSetup
{
WhenAssemblyKeyFileNotFound = ProjectSetupBehavior.Valid,
WhenContainsFileReferences = ProjectSetupBehavior.Valid,
WhenContainsProjectReferences = ProjectSetupBehavior.Warn,
WhenReferenceNotResolved = ProjectSetupBehavior.Warn,
WhenReferenceResolvedInDifferentLocation = ProjectSetupBehavior.Warn,
WhenRequiredProjectLinkNotFound = ProjectSetupBehavior.Valid
};
var consoleLogger = ConsoleLogger.Default;
var generator = new SolutionGenerator.Toolkit.SolutionGenerator(consoleLogger);
var projectLoader = generator.GetProjectLoader(projectSetup, configuration.RootPath);
var targetProjectFiles = generator.GetTargetProjectFiles(projectLoader, targetProjects);
ReferenceWalker walker = new ReferenceWalker(consoleLogger);
var dependencies = walker.WalkReferencesRecursively(
projectSetup, projectLoader, targetProjectFiles,
new[] {configuration.ThirdPartiesRootPath}, new HashSet<string>());
projectFiles = new List<FileSystemInfo>();
foreach (var dependency in dependencies)
{
var project = projectLoader.GetProjectById(dependency);
projectFiles.Add(new FileInfo(project.ProjectFileLocation));
}
}
ChangeOutputPath(projectFiles, configuration.RootPath, configuration.BinariesOutputPath, targetProjects);
ChangeReferences(projectFiles,
configuration.RootPath,
configuration.BinariesOutputPath,
configuration.TargetFrameworkVersion,
configuration.GetSystemRuntimeReferenceMode,
configuration.GetSpecificVersionReferenceMode,
targetProjects);
ChangeProjectSettings(projectFiles);
}