Skip to content

Commit 0c0dc87

Browse files
authored
[CleanRepo] Add ability to filter subfolders (#527)
1 parent b26d5a5 commit 0c0dc87

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

cleanrepo/Options.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ class Options
44
{
55
public string? DocFxDirectory { get; set; }
66
public string? TargetDirectory { get; set; }
7+
public string? Subdirectory { get; set; }
78
public string? UrlBasePath { get; set; }
89
public bool Delete { get; set; } = true;
910
public bool XmlSource { get; set; } = false;

cleanrepo/Program.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,11 @@ static async Task RunOptions(Options options)
277277
case "FindOrphanedSnippets":
278278
{
279279
Console.WriteLine($"\nSearching the '{options.TargetDirectory}' directory recursively for orphaned snippet files.");
280+
if (options.Subdirectory != null)
281+
Console.WriteLine($"Only searching subdirectories with '{options.Subdirectory}' in their path.");
280282

281283
// Get all snippet files.
282-
List<(string, string?)> snippetFiles = GetSnippetFiles(options.TargetDirectory);
284+
List<(string, string?)> snippetFiles = GetSnippetFiles(options.TargetDirectory, options.Subdirectory);
283285
if (snippetFiles.Count == 0)
284286
{
285287
Console.WriteLine("\nNo files with matching extensions were found.");
@@ -777,7 +779,7 @@ private static Dictionary<string, int> GetIncludeFiles(string inputDirectory)
777779
/// <summary>
778780
/// Returns a list of code files in the specified directory and its subdirectories.
779781
/// </summary>
780-
private static List<(string, string?)> GetSnippetFiles(string inputDirectory)
782+
private static List<(string, string?)> GetSnippetFiles(string inputDirectory, string? subdirectoryPattern)
781783
{
782784
List<string> fileExtensions = [".cs", ".vb", ".fs", ".cpp", ".xaml"];
783785

@@ -794,6 +796,13 @@ private static Dictionary<string, int> GetIncludeFiles(string inputDirectory)
794796

795797
foreach (DirectoryInfo subDirectory in dir.EnumerateDirectories("*", SearchOption.AllDirectories))
796798
{
799+
// If subdirectory pattern is specified, check for this string in the directory path.
800+
if (!string.IsNullOrEmpty(subdirectoryPattern) &&
801+
!subDirectory.FullName.Contains(subdirectoryPattern, StringComparison.OrdinalIgnoreCase))
802+
{
803+
continue; // Skip this subdirectory.
804+
}
805+
797806
foreach (string extension in fileExtensions)
798807
{
799808
foreach (FileInfo file in subDirectory.EnumerateFiles($"*{extension}"))

0 commit comments

Comments
 (0)