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

2

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

[deleted]

1

u/ProffesorCalculus Jul 29 '17

Yay! It works!

Thanks A LOT! :)