Skip to content

Commit

Permalink
Partially reverted changes in FrmRmWrk for better performance.
Browse files Browse the repository at this point in the history
  • Loading branch information
xvitaly committed Sep 2, 2024
1 parent b6020e5 commit 0499661
Showing 1 changed file with 18 additions and 43 deletions.
61 changes: 18 additions & 43 deletions src/srcrepair/FrmRmWrk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,47 +44,6 @@ public FrmRmWrk(List<string> SL)
RemDirs = SL;
}

/// <summary>
/// Finds files in the specified directory and adds them to the list.
/// </summary>
/// <param name="CleanDir">Directory for cleanup.</param>
/// <returns>The list of files for cleanup.</returns>
private List<string> AddFilesToList(string CleanDir)
{
List<string> Result = new List<string>();

foreach (string DItem in Directory.GetFiles(CleanDir))
{
Result.Add(DItem);
}

return Result;
}

/// <summary>
/// Finds subdirectories in the specified directory, recursively tries
/// to find files in it and add them to the list.
/// </summary>
/// <param name="CleanDir">Directory for cleanup.</param>
/// <returns>The list of files for cleanup.</returns>
private List<string> AddDirectoriesToList(string CleanDir)
{
List<string> Result = new List<string>();
List<string> SubDirs = new List<string>();

foreach (string SubDir in Directory.GetDirectories(CleanDir))
{
SubDirs.Add(SubDir);
}

if (SubDirs.Count > 0)
{
Result.AddRange(DetectFilesForCleanup(SubDirs));
}

return Result;
}

/// <summary>
/// Gets the full list of files for deletion.
/// </summary>
Expand All @@ -101,8 +60,24 @@ private List<string> DetectFilesForCleanup(List<string> CleanDirs)
// Checking for directory existence...
if (Directory.Exists(CleanCnd))
{
Result.AddRange(AddFilesToList(CleanCnd));
Result.AddRange(AddDirectoriesToList(CleanCnd));
// Getting files and adding them to the result...
foreach (string DItem in Directory.GetFiles(CleanCnd))
{
Result.Add(DItem);
}

// Getting subdirectories...
List<string> SubDirs = new List<string>();
foreach (string SubDir in Directory.GetDirectories(CleanCnd))
{
SubDirs.Add(SubDir);
}

// If at least one subdirectory exist, run this method recursively...
if (SubDirs.Count > 0)
{
Result.AddRange(DetectFilesForCleanup(SubDirs));
}
}
else
{
Expand Down

0 comments on commit 0499661

Please sign in to comment.