Error using BAT files. - R was unexpected at this time

This is the code:

call n:\xxx\xxx\variables.bat %1 %2 %3 %4 %5 %6

set yourZipPassword=%xxx%
set yourFolderPath="n:\xxxx\xxxx\%xxxx%"

for /R "%yourFolderPath%" %%I in ("*.zip") do (
  "C:\Program Files\7-Zip\7z.exe" x -p%yourZipPassword% -y -o"%%~dpI" "%%~fI" 
)

I do not know what to do with this error - " R was unexpected at the moment. "

And this bat file is stuck on this line and is no longer being processed:

for /R "%yourFolderPath%" %%I in ("*.zip") do (
+1
source share
1 answer

Change the syntax set...:

set yourFolderPath="n:\xxxx\xxxx\%xxxx%"

... to the following (in general):

set "yourFolderPath=n:\xxxx\xxxx\%xxxx%"

So, quotation marks are no longer part of the meaning. Since you have this in your question, loop for /R( for /R "%yourFolderPath%") gets the root path, for example for /R ""n:\xxxx\xxxx\%xxxx%"", therefore it is "retrained". This is a problem, especially if there are white spaces and / or special characters in the variable.


set : , , , - , :

set PDIR="D:\Data"
set FILE="file.ext"

:

echo unquoted: %PDIR%\%FILE%
echo quoted: "%PDIR%\%FILE%"

:

unquoted: "D:\Data"\"file.ext"
quoted: ""D:\Data"\"file.ext""

, . :

set "PDIR=D:\Data"
set "FILE=file.ext"

echo unquoted: %PDIR%\%FILE%
echo quoted: "%PDIR%\%FILE%"

, :

unquoted: D:\Data\file.ext
quoted: "D:\Data\file.ext"

, .


, , Windows cmd .

+4

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


All Articles