I want to rename lots of files to their md5. I've already write a bash script to do this job and use git-scm (https://git-scm.com/) to run the script in windows.
find WorkFolder -type f -iname '*.tif' -print0 |
while IFS= read -r -d '' file; do
hash=$(md5sum "$file"|cut -c1-32)
echo -e "\"$hash\"\t\"$file\"" >>dataPic.csv
mv "$file" "OutputFolder/$hash.tif"
done
This script do 2 jobs. 1. It calculate the file's md5, rename the file to md5.tif and move the result file to output folder. No matter how deep in subfolders the file placed. If two files have same md5, two source both deleted output folder keeps only one. 2. It also write a new line to csv file, every line's format is
<file's md5> <tab> <file's original full path and name>
It works well, but since files are more and more, the process speed is too slow now.
I'm trying to write a batch to do the same job. But I don't know if certutil -hashfile MD5
actually works faster than md5sum, or maybe slower. Writing batch is also harder than I thought.
I wrote a draft:
FOR /r .\sourcefolder %%i in (*.tif) do (
FOR /F %%F IN (`certutil -hashfile "%%i" SHA256 | findstr /V ":"`) DO (SET md5=%%F)
set /a line=%md5%+" "+%%i
echo %line% >>log.txt
rename %%i .\outputfolder\%md5%.tif
)