read a line from a txt file into a var , looping f.md5

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
zimbot
Posts: 7
Joined: 08 Nov 2018 14:05

read a line from a txt file into a var , looping f.md5

#1 Post by zimbot » 04 Mar 2019 11:37

frinds I need to make md5sums and also creat a txt file that is
hashvalue filename ; much like a bindry hash is hashvalue* filename
my current attempt is to
1- make the file.md5
2- read that finished txt file , file,md5 into a var
3- trim the first 32 char from that var

BUT my effort to read the file.md5 back into a var does not GET the string
?? what am i doing wrong ... and also ...is there a better way that i am not seeing

here is what i am doing
I ask the usr to drag in the dir that has the many files to make md5 for
all that is working fine .
my problem is the creation of the hash-list.txt

Code: Select all



@echo off
echo makes md5 hash

echo * ----------------------------------------------------------------------------*
echo *** You will be asked to drag here: ***
echo *** ***
echo ** just drag your dir to this shell , have focus in the shell and hit enter ***

echo I make md5sum hash checksums


set logfile=make-hash.txt

set /p srcDir=Drag your Source Directory here:%=%
@echo %scrcDir%
REM pause
cd /D %srcDir%
dir
REM pause

for /f %%a IN ('dir /b *.*') do (

echo hashing file %%a
rem makes md5 hash
REM -- and the below is working a OK  , these are made
md5sum -b %%a > %%a.md5

rem cleans file removes dos ^M carriage returns
dos2unix.exe %%a.md5

rem pull hash val full string
REM  THIS is what is not working
REM should not this work??   a %%.md5  does exist and is correct in all ways
rem set /p hashString=< %%a.md5

REM  i put this echo to try and see what is happening : i only get " my hash string is  "
echo my hash string is %hashString%
set hash=%hashString:~0,32%
echo %hash%

rem build hash_list.txt
echo %hash% %%a >> hash_list.txt

)

rem optional
rem cleans file removes dos ^M carriage returns
rem dos2unix.exe hash_list.txt

echo *******************************************************************************
echo *******************************************************************************

echo you may close this shell

pause





Squashman
Expert
Posts: 4107
Joined: 23 Dec 2011 13:59

Re: read a line from a txt file into a var , looping f.md5

#2 Post by Squashman » 04 Mar 2019 15:38

You are inside a parentheses code block. All environmental variables inside a code block are expanded to their values before any commands are executed. In order to have the environmental variables expanded at run time of the command, you need to use delayed expansion.

zimbot
Posts: 7
Joined: 08 Nov 2018 14:05

Re: read a line from a txt file into a var , looping f.md5

#3 Post by zimbot » 04 Mar 2019 16:50

thanks sqaushman...
coming from a mostly linux bash background ,,,, sometimes the win stuff stumbles me
that darn delayedexpansion -- got me again!

thanks

I got it working

Post Reply