r/programmingrequests • • Jul 27 '17

[Request] A simple program to delete files that have their hexadecimal hash in their filenames

I've exported .csv and .html files of the results of the duplicate images generated by Similarity which is a decent free software. Now the problem is that there are about 15'000 images that have duplicates renamed with their hashes in Hydrus Network.

I'm looking to keep the files with their original filenames, not ones that are renamed to their hashes. I can manually do this in Similarity, but since there are 15K files, it'll take a lot of time so I'm requesting a simple code to do that for me.

Any helps would be much appreciated.

2 Upvotes

30 comments sorted by

View all comments

Show parent comments

1

u/ProffesorCalculus Jul 28 '17

I used the second method (replacing del with move)and it worked just fine!

If I understood correctly, your code tells the computer to read the CSV file line by line and to calculate the hash of the each of the two files that are addressed in a line, then move/delete one of the addressed files which has the same filename as its calculated hash, right?

I'm going to delete the moved files, but just for a peace of mind, I'm gonna double check before that. What does the code do if there are two files in a line with the same 64 hex characters file name but one with a (1) after its name?

Is there a trustworthy way to code a program that would calculate the hash of every file in a folder, and do the same for files in another folder (two different folders thus two different directories) and then to delete the files that are repeated in the second folder?

I mean, I moved the files with your code to a folder named "moved". Now, I want to make sure that there is a copy of each file of "moved" in "xxx", and if the statement is true, then to delete that file from "moved".

2

u/[deleted] Jul 28 '17 edited Oct 06 '17

[deleted]

1

u/ProffesorCalculus Jul 28 '17

I ran the script with 3 files but it only displayed "Press any key to continue..." in CMD. I can confirm that it successfully created "temphashout.txt" by testing the script with more files, thus having much more time to see if the file appears or not.

I didn't understand what you meant in here:

set dir2=D:\path with spaces put no quotes around this var\move

and maybe that's where the script is not working. What is var\move?

Do you mean something like this? for a folder called "folder2"?

set dir2=D:\folder2 var\move

2

u/[deleted] Jul 28 '17 edited Oct 06 '17

[deleted]

1

u/ProffesorCalculus Jul 28 '17

OK, I got it, thanks. Unfortunately, the script doesn't work. I have 3 files in "folder1" and I copied those three into "folder2" but renamed them to something else. The script doesn't delete or detect anything to delete.

2

u/[deleted] Jul 28 '17 edited Oct 06 '17

[deleted]

1

u/ProffesorCalculus Jul 29 '17

Yes, it does, but still it doesn't delete.

Does it need to have the script inside one of the two directories?

2

u/[deleted] Jul 29 '17 edited Oct 06 '17

[deleted]

1

u/ProffesorCalculus Jul 29 '17

This is what I get after changing the script. Still, nothing happens but a temphashout.txt file is created in folder1. I checked again with other images but again, the script doesn't work.

2

u/[deleted] Jul 29 '17 edited Oct 06 '17

[deleted]

→ More replies (0)