Compare commits

..

2 Commits

Author SHA1 Message Date
101d128a42 release 0.7 2025-05-11 03:08:31 +02:00
82160b12e1 implemented delteingnonexistentFiles from DB 2025-05-11 03:06:23 +02:00
3 changed files with 49 additions and 3 deletions

BIN
0.7.zip Normal file

Binary file not shown.

View File

@ -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"
} }
} }
} }

View File

@ -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