本文整理汇总了C#中IDirectory.Populate方法的典型用法代码示例。如果您正苦于以下问题:C# IDirectory.Populate方法的具体用法?C# IDirectory.Populate怎么用?C# IDirectory.Populate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDirectory
的用法示例。
在下文中一共展示了IDirectory.Populate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: foreach
/*public static void GetFilesForImportFolder(string folderLocation, ref List<string> fileList)
{
if (Directory.Exists(folderLocation))
{
// get root level files
fileList.AddRange(Directory.GetFiles(folderLocation, "*.*", SearchOption.TopDirectoryOnly));
// search sub folders
foreach (string dirName in Directory.GetDirectories(folderLocation))
{
try
{
if (dirName.ToUpper().Contains("RECYCLE.BIN")) continue;
fileList.AddRange(Directory.GetFiles(dirName, "*.*", SearchOption.AllDirectories));
}
catch (Exception ex)
{
logger.Warn("Error accessing: {0} - {1}", dirName, ex.Message);
}
}
}
}*/
public static void GetFilesForImportFolder(IDirectory sDir, ref List<string> fileList)
{
try
{
if (sDir == null)
{
logger.Error("Filesystem not found");
return;
}
// get root level files
FileSystemResult r = sDir.Populate();
if (r == null || !r.IsOk)
{
logger.Error($"Unable to retrieve folder {sDir.FullName}");
return;
}
fileList.AddRange(sDir.Files.Select(a => a.FullName));
// search sub folders
foreach (IDirectory dir in sDir.Directories)
{
GetFilesForImportFolder(dir, ref fileList);
// bool isSystem = (di.Attributes & FileAttributes.System) == FileAttributes.System;
// if (isSystem)
// continue;
}
}
catch (Exception excpt)
{
Console.WriteLine(excpt.Message);
}
}
示例2: RecursiveDeleteEmptyDirectories
private void RecursiveDeleteEmptyDirectories(IDirectory dir, bool importfolder)
{
FileSystemResult fr = dir.Populate();
if (fr.IsOk)
{
if (dir.Files.Count > 0)
return;
foreach (IDirectory d in dir.Directories)
RecursiveDeleteEmptyDirectories(d,false);
}
if (importfolder)
return;
fr = dir.Populate();
if (fr.IsOk)
{
if (dir.Files.Count == 0 && dir.Directories.Count == 0)
{
fr = dir.Delete(true);
if (!fr.IsOk)
{
logger.Warn("Unable to DELETE directory: {0} error {1}", dir.FullName, fr?.Error ?? String.Empty);
}
}
}
}