For /f processing filename with spaces

☆樱花仙子☆ 提交于 2019-11-30 01:00:20

问题


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?


回答1:


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.




回答2:


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
)


来源:https://stackoverflow.com/questions/5006290/for-f-processing-filename-with-spaces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!