Path with spaces in the batch file loop

I am trying to execute this command:

for /f "tokens=3 usebackq" %%i in (`"%~dp0imagex.exe" /info "%~dp0DVD\sources\install.wim" ^| findstr /c:"Image Count:"`) do set ImageCount=%%i echo %ImageCount% 

I get an error if the path% ~ dp0 contains spaces like "D: \ my work". Although I used usebackq and a back quote instead of a single quote.

error message: "D: \ my" is not recognized as an internal or external command, operating program, or batch file.

What happened on my team?

+4
source share
1 answer

If this does not work:

 for /f "tokens=3 usebackq" %%i in (`"%~dp0imagex.exe" /info "%~dp0DVD\sources\install.wim" ^| findstr /c:"Image Count:"`) do set ImageCount=%%i echo %ImageCount% 

Try the following:

 pushd %~dp0 for /f "tokens=3 usebackq" %%i in (`imagex.exe" /info "DVD\sources\install.wim" ^| findstr /c:"Image Count:"`) do set ImageCount=%%i echo %ImageCount% popd 
+2
source

Source: https://habr.com/ru/post/1432266/


All Articles