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

2

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

[deleted]

1

u/ProffesorCalculus Jul 27 '17

Thanks a lot, but you misunderstood it. I meant I have one directory "D:\xxx" which has about 35000 media files in it and there are about 15000 duplicate images. I have a CSV file that contains two directories in each line (the file contains 15200 lines) when opened by Notepad++, like this:

"D:\xxx\62b5111373509d456ea2bc9ad008a4f838fc9da0d4f859a053ebeae8bdd54f1a.jpg";"D:\xxx\3270466_5_o.jpg";100.0000;100.0000

Which means the two files have the same content (those two 100.0000 at the end of the line indicate it). Now, I want to delete the file that has a 64 hex charactered name and keep the other, in each line of the CSV list.

2

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

[deleted]

1

u/ProffesorCalculus Jul 27 '17

Yes, every line has this structure:

"Directory 1";"Directory 2";% content;% experim

Which as I said, the two percentages are not important at all.

I don't think there would be much of a chance to have two files with the same 64 hex character file names in a line or two files both of them having some 64 characters hashes in their file names, but I'm not %100 sure. Maybe it would be better to have the program check if the two directories (file names) in a line are not both 64 characters hex hashes.

I meant to delete the actual file.

2

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

[deleted]

1

u/ProffesorCalculus Jul 27 '17

Another option would be (similar to my first script) check if the file is not a hash file name, generate the hash of that file with certutil, and delete any file that is named after the hash.

This seems great, would you please post its code?

Am I supposed to copy the code into notepad and save it as a .bat file inside the directory which has all the images and the .csv file in it?

2

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

[deleted]

1

u/ProffesorCalculus Jul 27 '17

Thank you so much! I tested it with some of my files and it worked. Is there any way to move the detected files to recycle bin instead of permanently deleting the files?

2

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

[deleted]

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".

→ More replies (0)