0

Well after tinkering with my batch compressionscript i also tried to fire up some paths with spaces and as always problems arise. Im trying to generate md5 hashes for comparison reasons before fireing up the compressor. Therefor i need to loop over every file to generate a hashsum. (for anyone interested heres my whole script : https://pastebin.com/qgWC4mY8)

Folder = working Directory

fileToCompress = folder inside working directory with files to generate checksum from

setlocal enabledelayedexpansion
...
echo Hashing a Folder
cd "%fileToCompress%"

for /R %%f in (*.*) do (

    REM hashing the found file and saving the hash in variable
    for /f "usebackq delims=" %%i in (`"%~dp0\md5.exe" -n "%%f"`) do set "hash=%%i"

    REM removing leading absolut path with advanced nested for loops
    Set "OldPath=%%f"
    for %%b in ("!Folder!") do set "str2=!OldPath:%%~b=!"
    Echo !hash! !str2! 
    ECHO !hash! !str2!  >> "%~dp0\compress_hash.txt"
)
cd "%~dp0"

my problem lies in the second for loop :

for /f "usebackq delims=" %%i in (`"%~dp0\md5.exe" -n "%%f"`) do set "hash=%%i"

As i need to absolut reference the md5.exe and the file %%f to hash corretly. So i need to enshure that the leading command path is seen as the main command and the filepath %%f is seen as one absolut path to a file to hash.

Long story short. Whatever i do either the second path isn't enclosed as one single parameter, or if i enclose both with doublequotes, the main command loses enclosure. Is this a bug/missing feature in batch scripting? Are multiple quoted strings allowed?

edit 1: The errors are either : (fail to encapsule main command)

Der Befehl "J:\Extracted\FINAL" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.

or fail to encapsule %%f with spaces so the md5.exe cant find the path:

Cannot open input file J:\Extracted\Ultima

edit 2: SOLUTION well it sees u need even more quotes to enshure the call get executed enclosed in another cmd:

for /f "delims=" %%i in ('""%~dp0\md5.exe" -n "%%f""') do set "hash=%%i"
jan b
  • 29
  • 7
  • So you are not getting any errors? Hard to troubleshoot without seeing what the batch file is doing. – Squashman Sep 08 '17 at 03:26
  • This doesn't solve your problem but I thought you might be interested in this hashsum technique. http://www.dostips.com/forum/viewtopic.php?t=7592 – Squashman Sep 08 '17 at 03:41
  • I think [this](https://stackoverflow.com/a/22636725/2861476) should help you – MC ND Sep 08 '17 at 09:20
  • @MC ND thx for the link might have missed that. even more quotes solved the problem ^^ – jan b Sep 08 '17 at 17:27

0 Answers0