Skip to content

Commit

Permalink
Switched ExpandFileList() public static method of the FileManager cla…
Browse files Browse the repository at this point in the history
…ss to EnumerateFiles() use.
  • Loading branch information
xvitaly committed Sep 4, 2024
1 parent 98965d3 commit d6e6963
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions src/corelib/FileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,36 +276,26 @@ public static List<string> FindFiles(string SearchPath, string SrcMask)
/// Finds files by specified mask in specified directories. Mask must be
/// added to the end of path.
/// </summary>
/// <param name="CleanDirs">List of directories with masks.</param>
/// <param name="DirList">List of directories with masks.</param>
/// <param name="IsRecursive">Use recursive (include subdirectories) search.</param>
/// <returns>List of files with full paths, matches mask.</returns>
public static List<string> ExpandFileList(List<string> CleanDirs, bool IsRecursive)
public static List<string> ExpandFileList(List<string> DirList, bool IsRecursive)
{
List<string> Result = new List<string>();
foreach (string DirMs in CleanDirs)
foreach (string DirMs in DirList)
{
string CleanDir = Path.GetDirectoryName(DirMs); string CleanMask = Path.GetFileName(DirMs);
if (Directory.Exists(CleanDir))
string CleanDir = Path.GetDirectoryName(DirMs);
string CleanMask = Path.GetFileName(DirMs);

try
{
try
if (!Directory.Exists(CleanDir)) { continue; }
foreach (string DItem in Directory.EnumerateFiles(CleanDir, CleanMask, IsRecursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly))
{
DirectoryInfo DInfo = new DirectoryInfo(CleanDir);
FileInfo[] DirList = DInfo.GetFiles(CleanMask);
foreach (FileInfo DItem in DirList) { Result.Add(DItem.FullName); }

if (IsRecursive)
{
try
{
List<string> SubDirs = new List<string>();
foreach (DirectoryInfo Dir in DInfo.GetDirectories()) { SubDirs.Add(Path.Combine(Dir.FullName, CleanMask)); }
if (SubDirs.Count > 0) { Result.AddRange(ExpandFileList(SubDirs, true)); }
}
catch (Exception Ex) { Logger.Warn(Ex); }
}
Result.Add(DItem);
}
catch (Exception Ex) { Logger.Warn(Ex); }
}
catch (Exception Ex) { Logger.Warn(Ex); }
}
return Result;
}
Expand Down

0 comments on commit d6e6963

Please sign in to comment.