Skip to content

Commit

Permalink
cleanup AddFilesFromDirectory (#4049)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored Nov 12, 2024
1 parent a8122b3 commit 87aed30
Showing 1 changed file with 5 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,14 @@ public virtual string CopyFileOverwrite(string source, string destination, out s

public virtual List<string> AddFilesFromDirectory(string directoryPath, Func<string, bool>? ignoreDirectory, bool ignoreIOExceptions)
{
var fileContents = new List<string>();
var files = new List<string>();

try
{
string[] files = GetFilesInADirectory(directoryPath);
fileContents.AddRange(files);
files.AddRange(GetFilesInADirectory(directoryPath));
}
catch (IOException)
catch (IOException) when (ignoreIOExceptions)
{
if (!ignoreIOExceptions)
{
throw;
}
}

foreach (string subDirectoryPath in GetDirectoriesInADirectory(directoryPath))
Expand All @@ -204,14 +199,10 @@ public virtual List<string> AddFilesFromDirectory(string directoryPath, Func<str
continue;
}

List<string> subDirectoryContents = AddFilesFromDirectory(subDirectoryPath, ignoreDirectory, true);
if (subDirectoryContents.Count > 0)
{
fileContents.AddRange(subDirectoryContents);
}
files.AddRange(AddFilesFromDirectory(subDirectoryPath, ignoreDirectory, true));
}

return fileContents;
return files;
}

public static string TryConvertPathToRelative(string path, string rootDir)
Expand Down

0 comments on commit 87aed30

Please sign in to comment.