Update deletion behavior and fixed file == NULL bug

This commit is contained in:
BlyDoesCoding 2023-03-20 21:31:10 +01:00
parent 6ade226c89
commit 335b2d81d8
2 changed files with 35 additions and 20 deletions

34
.idea/workspace.xml generated
View file

@ -10,7 +10,8 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="9b57ac51-c870-474b-9dfd-64a5fc490635" name="Changes" comment="Rework of README.md"> <list default="true" id="9b57ac51-c870-474b-9dfd-64a5fc490635" name="Changes" comment="Rework of README.md">
<change beforePath="$PROJECT_DIR$/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/README.md" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Main.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Main.java" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -54,18 +55,18 @@
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent">{ <component name="PropertiesComponent"><![CDATA[{
&quot;keyToString&quot;: { "keyToString": {
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;, "RunOnceActivity.OpenProjectViewOnStart": "true",
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;, "RunOnceActivity.ShowReadmeOnStart": "true",
&quot;SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;, "SHARE_PROJECT_CONFIGURATION_FILES": "true",
&quot;last_opened_file_path&quot;: &quot;/home/bly/IdeaProjects/Sherly&quot;, "last_opened_file_path": "/home/bly/IdeaProjects/Sherly",
&quot;project.structure.last.edited&quot;: &quot;Artifacts&quot;, "project.structure.last.edited": "Artifacts",
&quot;project.structure.proportion&quot;: &quot;0.15&quot;, "project.structure.proportion": "0.15",
&quot;project.structure.side.proportion&quot;: &quot;0.2&quot;, "project.structure.side.proportion": "0.2",
&quot;settings.editor.selected.configurable&quot;: &quot;vcs.Git&quot; "settings.editor.selected.configurable": "Settings.Markdown"
} }
}</component> }]]></component>
<component name="RunAnythingCache"> <component name="RunAnythingCache">
<option name="myCommands"> <option name="myCommands">
<command value="github" /> <command value="github" />
@ -200,7 +201,14 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1679341913990</updated> <updated>1679341913990</updated>
</task> </task>
<option name="localTasksCounter" value="16" /> <task id="LOCAL-00016" summary="Rework of README.md">
<created>1679341943299</created>
<option name="number" value="00016" />
<option name="presentableId" value="LOCAL-00016" />
<option name="project" value="LOCAL" />
<updated>1679341943299</updated>
</task>
<option name="localTasksCounter" value="17" />
<servers /> <servers />
</component> </component>
<component name="Vcs.Log.Tabs.Properties"> <component name="Vcs.Log.Tabs.Properties">

View file

@ -49,7 +49,7 @@ public class Main {
System.out.println(" -f / -folder all the folders you want to scan for (see example above!)"); System.out.println(" -f / -folder all the folders you want to scan for (see example above!)");
System.out.println(" -c / -color enable colored messages"); System.out.println(" -c / -color enable colored messages");
System.out.println(" -p / -progress enable progress indicator"); System.out.println(" -p / -progress enable progress indicator");
System.out.println(" -d / -delete delete all found duplicates except one"); System.out.println(" -d / -delete delete all dups except one without asking first");
System.out.println(" -debug debug stuff"); System.out.println(" -debug debug stuff");
return; return;
} }
@ -119,9 +119,9 @@ public class Main {
TimeUnit.SECONDS.sleep(1); TimeUnit.SECONDS.sleep(1);
if (showProgress && doTheColorThingy) { if (showProgress && doTheColorThingy) {
System.out.print(ConsoleColors.BLUE_BOLD + "Progress: " + ConsoleColors.GREEN_BOLD + progress + " / " + filesToBeDone + ConsoleColors.RESET + "\r"); System.out.print(ConsoleColors.BLUE_BOLD + "Progress: " + ConsoleColors.GREEN_BOLD + progress + " / " + filesToBeDone + " | " + (progress * 100 / filesToBeDone) + "%" + ConsoleColors.RESET + "\r");
} else if (showProgress) { } else if (showProgress) {
System.out.print("Progress: " + progress + " / " + filesToBeDone + "\r"); System.out.print("Progress: " + progress + " / " + filesToBeDone + " | " + (progress * 100 / filesToBeDone) + "%" + "\r");
} }
} }
@ -140,7 +140,7 @@ public class Main {
} }
if (deleteDups) {
List<Path> allTheFilesWillBeDeleted = new ArrayList<>(); List<Path> allTheFilesWillBeDeleted = new ArrayList<>();
long bytes = 0; long bytes = 0;
@ -159,9 +159,14 @@ public class Main {
ask(doTheColorThingy, bytes, allTheFilesWillBeDeleted); if (deleteDups) {
delete(allTheFilesWillBeDeleted);
} else {
ask(doTheColorThingy, bytes, allTheFilesWillBeDeleted);
}
}
} }
//print files and ask user //print files and ask user
@ -188,7 +193,9 @@ public class Main {
public static void delete(List<Path> deleteThem) { public static void delete(List<Path> deleteThem) {
for (Path file : deleteThem) { for (Path file : deleteThem) {
file.toFile().delete(); if (file != null) {file.toFile().delete();}
} }
} }