For /f processing filename with spaces

2019-02-16 08:38发布

I want to do some processing on each line of a file.

for /f "delims=" %%i in ("%RF_PROPERTIES%") do (          
   echo %%i
)

My RF_PROPERTIES points to a file path with spaces (c:\program files\Arcot systems\conf\rf.properties). It is complaining saying Environment variable C:\Program Files\Arcot not defined, even though I have provided quotes. How to get it working?

2条回答
等我变得足够好
2楼-- · 2019-02-16 08:56

Using usebackq is a good idea - but you actually have to use them :

for /f "usebackq delims=" %%i in ( `dir "%RF_PROPERTIES%" /s /b` ) do (
  echo %%i
)
查看更多
三岁会撩人
3楼-- · 2019-02-16 09:08

Try adding the usebackq option:

for /f "usebackq delims=" %%i in ("%RF_PROPERTIES%") do (          
  echo %%i
)

Explanation from the output of for /?:

usebackq - specifies that the new semantics are in force, where a back quoted string is executed as a command and a single quoted string is a literal string command and allows the use of double quotes to quote file names in file-set.

查看更多
登录 后发表回答