Question

I have a folder with a few zip files called 1.zip, 2.zip and so on.

The folder also has md5 files for each zip like this 1.zip.md5 ... n.zip.md5

md5 files have the md5sum in uppercase with a new line at the end

I am trying to write a batch program that will read all zip files, compute the md5sum of them and compare it to the one in the associated md5 file.

I have gotten this far.

@echo off
set mypath=G:\Temp\

for %%f in (*.zip) do (
  echo PROCESSING: %mypath%%%f
  md5sum < %mypath%%%f > %mypath%%%f.tmp
  set /p sum=<%mypath%%%f.tmp
  echo SUM: %sum%
  :rm %mypath%%%f.tmp
  pause
)
pause

My problem is that set /p sum=<%mypath%%%f.tmp does not seem to get the contents for some reason.

On top of that md5sum outputs lowercase md5sum and followed by *-.

I am new in batch and already spent too many hours trying to figure this out.

Can someone give me some tips on what am I doing wrong and how I might be able to do some debugging when I get stuck again?

After I get over this I will need to split the tpm file contents by space to separate the md5sum and uppercase it. Hope that will be easy them compare should be even easier.

Thank you.

Was it helpful?

Solution

@echo off
set mypath=.
rem cd /d "%mypath%"
setlocal enableDelayedExpansion
for %%f in (*.zip) do (
  echo PROCESSING: %%~dpfnxf
  for /f "tokens=1 delims=*- " %%S in ('md5sum ^< "%%~dpfnxf" ') do set "sum=%%S" 
  echo SUM: !sum!
  :rm %mypath%%%f.tmp
  pause
)
endlocal
pause
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top