Compare commits
No commits in common. "101d128a424bcdd89a8ada6c253c83c35d6b80f0" and "e0ed86899c30aa9f764851713bf651de4ce0a1ef" have entirely different histories.
101d128a42
...
e0ed86899c
@ -10,11 +10,11 @@
|
||||
},
|
||||
"Delete": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "delete redundancies.json C:\\Users\\daskn\\Pictures\\ -v"
|
||||
"commandLineArgs": "delete redundancies.json C:\\Users\\daskn\\Pictures\\B\\ -v"
|
||||
},
|
||||
"Sanitize": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "sanitize C:\\Users\\daskn\\Pictures\\ -v -d redundancies.json"
|
||||
"commandLineArgs": "sanitize C:\\Users\\daskn\\Pictures\\ -v"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
@ -27,63 +26,18 @@ namespace RedundancyFinderCLI
|
||||
[DefaultValue(false)]
|
||||
public bool Verbose { get; init; }
|
||||
|
||||
[Description("Show all information.")]
|
||||
[CommandOption("-d|--deleteNonExistent <pathToSource>")]
|
||||
[DefaultValue("redundancies.json")]
|
||||
public string? PathToSource { get; init; }
|
||||
|
||||
}
|
||||
|
||||
Settings settings = null;
|
||||
public override int Execute([NotNull] CommandContext context, [NotNull] Settings settings)
|
||||
{
|
||||
this.settings = settings;
|
||||
Global.WriteLine($"[white]Sanitizing {settings.Path}[/]");
|
||||
Global.WriteLine($"[yellow]Deleting empty folders[/]");
|
||||
int count = DeleteEmptyFolders(settings.Path);
|
||||
if (File.Exists(settings.PathToSource))
|
||||
{
|
||||
DeleteNonExistentPaths();
|
||||
}
|
||||
|
||||
Global.WriteLine($"[green]Deleted [/]{count}[green] empty folders[/]");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void DeleteNonExistentPaths()
|
||||
{
|
||||
Dictionary<string, Redundancy> redundancies = null;
|
||||
|
||||
|
||||
AnsiConsole.Status()
|
||||
.Start($"[yellow]Loading [/]'{settings.PathToSource}'", ctx =>
|
||||
{
|
||||
ctx.Spinner(Spinner.Known.Clock);
|
||||
ctx.SpinnerStyle = Style.Parse("yellow bold");
|
||||
Thread.Sleep(1000);
|
||||
redundancies = JsonConvert.DeserializeObject<Dictionary<string, Redundancy>>(File.ReadAllText(settings.PathToSource));
|
||||
|
||||
});
|
||||
|
||||
foreach (var redundancy in redundancies)
|
||||
{
|
||||
var paths = redundancy.Value.Paths;
|
||||
foreach (var path in paths.ToList())
|
||||
{
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
Global.WriteLine($"[red]Deleting non existent file: {path}[/]");
|
||||
|
||||
redundancy.Value.Paths.Remove(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var json = JsonConvert.SerializeObject(redundancies, Formatting.Indented);
|
||||
File.WriteAllText(settings.PathToSource, json);
|
||||
}
|
||||
|
||||
|
||||
public static int DeleteEmptyFolders(string directoryPath, int count = 0)
|
||||
{
|
||||
try
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user