Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
First off I'm trying to use a command line md5 hash finder to get the md5 hash of a picture then rename the picture to the md5 hash using batch.
When I get a txt file with the picture names and md5 there is also some extra lines of information put in by the md5 program. I would like to be able to remove those lines from the txt. How would I start doing that.
After only the names and md5 of the pictures are left in the txt i'd like to rename the file with the md5.
here is an example of the txt without the extra lines
1188454269070.jpg 721fbfd2682daea798e7dafe0f5c0e92
1190221107488.jpg 014a19a63a4028245fdc65a2c9819beb
1190224549110.jpg bea46ead775f3fbfae81c4418c5bc5b1
1190502027485.jpg e49a35c2581cc85c4e17e277c602b0f5Is there a way to rename the file to the md5 that is assigned to the file name in the txt.
This is what I have so far for the batch file
for /f "tokens=*" %%x in ('dir /b *.jpg') do ("e:\pics\md5sums.exe" -n -b "%%x" >>%cd%\log.txt)
and the current output
MD5sums 1.2 freeware for Win9x/ME/NT/2000/XP+
Copyright (C) 2001-2005 Jem Berkes - http://www.pc-tools.net/1188454269070.jpg 721fbfd2682daea798e7dafe0f5c0e92
MD5sums 1.2 freeware for Win9x/ME/NT/2000/XP+
Copyright (C) 2001-2005 Jem Berkes - http://www.pc-tools.net/1190221107488.jpg 014a19a63a4028245fdc65a2c9819beb
MD5sums 1.2 freeware for Win9x/ME/NT/2000/XP+
Copyright (C) 2001-2005 Jem Berkes - http://www.pc-tools.net/1190224549110.jpg bea46ead775f3fbfae81c4418c5bc5b1
MD5sums 1.2 freeware for Win9x/ME/NT/2000/XP+
Copyright (C) 2001-2005 Jem Berkes - http://www.pc-tools.net/1190502027485.jpg e49a35c2581cc85c4e17e277c602b0f5
note file name and md5 are on the same line in the txt file

I don't have a command line md5. [Maybe you can post a link to one.] But I suppose it works much like a CRC utility. If so, try this:
::==
@echo off
setLocal EnableDelayedExpansionfor /f "tokens=1-2 delims= " %%a in ('crc32.exe my.jpg ^|find "MY.JPG"') do (
cls
echo %%b %%a >> %%a.txt
echo ren %%b %%a.jpg
)
=====================================
If at first you don't succeed, you're about average.M2

@echo off
for /f "tokens=*" %%i in ('dir /b *.jpg') do (
for %%j in ('E:\pics\md5sums -n -b "%%i" ^| Find /I "jpg"') do (
ren "%%i" %%j
)
)

I tried both and could not get them to work so I'm gonna try some more.
Here is the link to the md5 program I am using http://www.pc-tools.net/win32/md5sums/

@echo off
for /f "tokens=*" %%i in ('dir /b *.jpg') do (
for /f "tokens=2" %%j in ('E:\pics\md5sums -n -b "%%i" ^| find /I ".jpg"') do (
ren "%%i" %%j.jpg
)
)

Thanks IVO
that works great, only problem is if the file name has a space it will rename the file to that second part, but that isn't a big deal. I can just run it a second time.
Thanks again

In Italy now time is late night, so I'll answer (I hope to achieve what you want) tomorrow. Just I don't understand the md5 renaming issue as the script looks for .jpg files and ... there are md5.jpg archives in the directory?
good night (for now)

Forget about that confusing stuff i said
if the original name is the same as what it wants to rename it to there is no problem so i'll just leave itAs I said earlier the only real problem is if the name has a space in it such as
one two three.jpg the batch script would rename it to two.jpg since that is the second word there. I have no clue how to fix that since i'm the one asking for help as it is.

The following script is an improved version of my original one, faster and renaming correctly files with embedded spaces.
@echo off
setlocal EnableDelayedExpansion
for /f "delims=" %%i in ('dir /b *.jpg') do (
for /f "skip=3 delims=" %%j in ('E:\pics\md5sums -n -b "%%i"') do (
set file=%%j
set file=!file:*.jpg=!
for %%k in (!file!) do ren "%%i" "%%k.jpg"
)
)

I'm playing with this batch file again and was wondering if someone could tell me how to have it process files in the folders as the same directory as the script.
So if I have the script in c:\ it'd only work on files in c:\folder and every other folder in c:\
also if there is a duplicate file and is there an easy way to delete the file that was trying to be renamed. Is there an error code returned when "A duplicate file name exists, or the file cannot be found." is returned since the file name is already used so you could say delete when that happens?

![]() |
How I can handle Window e...
|
2 questions, 1 post
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |