diff --git a/DotNetSolutionTools.App/ViewModels/MainWindowViewModel.cs b/DotNetSolutionTools.App/ViewModels/MainWindowViewModel.cs index 104be19..6e8cda7 100644 --- a/DotNetSolutionTools.App/ViewModels/MainWindowViewModel.cs +++ b/DotNetSolutionTools.App/ViewModels/MainWindowViewModel.cs @@ -135,6 +135,24 @@ public partial class MainWindowViewModel : ViewModelBase ParityResults?.Add(e.Message); } } + + [RelayCommand] + private async Task DeleteBinAndObjFoldersInFolder(CancellationToken token) + { + ErrorMessages?.Clear(); + ParityResults.Clear(); + ResultsLabel = string.Empty; + try + { + CleanFolder.DeleteFolderWithOnlyBinAndObjSubFolders(SolutionFolderPath); + ResultsLabel = "Successfully deleted bin and obj folders"; + } + catch (Exception e) + { + ResultsLabel = "Failed to delete bin and obj folders"; + ParityResults?.Add(e.Message); + } + } [RelayCommand] private async Task LoadSolutionFile(CancellationToken token) diff --git a/DotNetSolutionTools.App/Views/MainWindow.axaml b/DotNetSolutionTools.App/Views/MainWindow.axaml index 9004d12..c9b317d 100644 --- a/DotNetSolutionTools.App/Views/MainWindow.axaml +++ b/DotNetSolutionTools.App/Views/MainWindow.axaml @@ -31,7 +31,7 @@ - + + diff --git a/DotNetSolutionTools.Core/CleanFolder.cs b/DotNetSolutionTools.Core/CleanFolder.cs new file mode 100644 index 0000000..1524ebc --- /dev/null +++ b/DotNetSolutionTools.Core/CleanFolder.cs @@ -0,0 +1,17 @@ + +namespace DotNetSolutionTools.Core; + +public static class CleanFolder +{ + public static void DeleteFolderWithOnlyBinAndObjSubFolders(string folderPath) + { + var binAndObjFolders = Directory.GetDirectories(folderPath, "*", SearchOption.AllDirectories) + .Where(x => x.EndsWith(Path.DirectorySeparatorChar + "bin") || x.EndsWith(Path.DirectorySeparatorChar + "obj")) + .ToList(); + + foreach (var folder in binAndObjFolders) + { + Directory.Delete(folder, true); + } + } +} \ No newline at end of file