Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
595 views
in Technique[技术] by (71.8m points)

file - For /f processing filename with spaces

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 filesArcot systemsconf f.properties). It is complaining saying Environment variable C:Program FilesArcot not defined, even though I have provided quotes. How to get it working?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...