Compare commits
2 Commits
e0ed86899c
...
101d128a42
| Author | SHA1 | Date | |
|---|---|---|---|
| 101d128a42 | |||
| 82160b12e1 |
@ -10,11 +10,11 @@
|
|||||||
},
|
},
|
||||||
"Delete": {
|
"Delete": {
|
||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"commandLineArgs": "delete redundancies.json C:\\Users\\daskn\\Pictures\\B\\ -v"
|
"commandLineArgs": "delete redundancies.json C:\\Users\\daskn\\Pictures\\ -v"
|
||||||
},
|
},
|
||||||
"Sanitize": {
|
"Sanitize": {
|
||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"commandLineArgs": "sanitize C:\\Users\\daskn\\Pictures\\ -v"
|
"commandLineArgs": "sanitize C:\\Users\\daskn\\Pictures\\ -v -d redundancies.json"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
@ -26,18 +27,63 @@ namespace RedundancyFinderCLI
|
|||||||
[DefaultValue(false)]
|
[DefaultValue(false)]
|
||||||
public bool Verbose { get; init; }
|
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)
|
public override int Execute([NotNull] CommandContext context, [NotNull] Settings settings)
|
||||||
{
|
{
|
||||||
|
this.settings = settings;
|
||||||
Global.WriteLine($"[white]Sanitizing {settings.Path}[/]");
|
Global.WriteLine($"[white]Sanitizing {settings.Path}[/]");
|
||||||
Global.WriteLine($"[yellow]Deleting empty folders[/]");
|
Global.WriteLine($"[yellow]Deleting empty folders[/]");
|
||||||
int count = DeleteEmptyFolders(settings.Path);
|
int count = DeleteEmptyFolders(settings.Path);
|
||||||
|
if (File.Exists(settings.PathToSource))
|
||||||
|
{
|
||||||
|
DeleteNonExistentPaths();
|
||||||
|
}
|
||||||
Global.WriteLine($"[green]Deleted [/]{count}[green] empty folders[/]");
|
Global.WriteLine($"[green]Deleted [/]{count}[green] empty folders[/]");
|
||||||
|
|
||||||
return 0;
|
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)
|
public static int DeleteEmptyFolders(string directoryPath, int count = 0)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user