Page 1 of 1

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

Posted: 04 Mar 2019 11:37
by zimbot
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





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

Posted: 04 Mar 2019 15:38
by Squashman
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.

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

Posted: 04 Mar 2019 16:50
by zimbot
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