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

2

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

[deleted]

1

u/ProffesorCalculus Jul 29 '17

Yes. I even created an empty text document and copied it into the second folder.

2

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

[deleted]

1

u/ProffesorCalculus Jul 29 '17

Maybe it's because you're on Windows 7 and I'm on Windows 10?

I added that piece, nothing changed in the CMD (nothing additional to the previous ones).

I'm not wasting my time, I love to see it work!

2

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

[deleted]

1

u/ProffesorCalculus Jul 29 '17

Apparently, adding a pause below :hashcheck makes no difference.

Also for adding echo %1.

What do you mean by saying the directory must be empty? What should I do?

2

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

[deleted]

1

u/ProffesorCalculus Jul 29 '17

Folder 2 is like folder 1 and it has 3 images inside of it. I don't know what do you mean by "there are no files".

I replaced with your last piece of code and here is the results (there is a pair of 3 images each pair in a folder, I renamed them from "1" to "6", "1" to "3" are in folder1 and the rest are in folder2):

Found dir 1 !
Press any key to continue . . .
Found dir 2 !
Press any key to continue . . .
"D:\folder2\4.jpg"::del: CertUtil: The system cannot find the file specified.
"D:\folder2\5.jpg"::del: CertUtil: The system cannot find the file specified.
"D:\folder2\6.jpg"::del: CertUtil: The system cannot find the file specified.
Press any key to continue . . .

1

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

[deleted]

1

u/ProffesorCalculus Jul 29 '17

Thank you. This is the code:

@echo off
setlocal


set dir1=D:\folder1
if exist "%dir1%" echo Found dir 1 !&pause
set dir2=D:\folder2 
if exist "%dir2%" echo Found dir 2 !&pause


for %%# in ("%dir1%\*") do certutil -hashfile "%%#" SHA256>>"%dir1%\temphashout.txt"
for /r "%dir2%" %%# in (*) do call :hashcheck "%%#"::del "%dir1%\temphashout.txt"
pause
exit /b

:hashcheck
for /f "skip=1 delims=" %%# in ('certutil -hashfile %1 SHA256') do set hash=%%#&goto b
:b
findstr /c:"%hash%" "%dir1%\temphashout.txt">nul&&echo del %1
echo %1: %hash%
→ More replies (0)