2012-01-18 16 views
0

ファイルの行を反復処理する必要があります。次のコマンドは機能しません。エスケープ ")"ウィンドウのバッチ "コマンドの"

set filename=c:\program files (x86)\somewhere 
... 
for /f "delims==" %%i in (%filename%) do echo %%i 

ファイル名に ")"が含まれています。エラー:

\somewhere) was unexpected at this time. 

インラインファイル名の代わりに変数を使用する必要があるため、「^」でエスケープするとここでは機能しません。これを解決するには?

答えて

4

二重引用符でファイル名を入れて、だけでなく、usebackqオプション追加:FOR /?の出力から

set filename=c:\program files (x86)\somewhere 
for /f "usebackq delims==" %%i in ("%filename%") do echo %%i 

を:

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. 
+0

あなたは私のように3秒笑って私を倒す必要があった – Mechaflash

+0

@Mechaflash:あなたの答えは私のものと同じです。だから+1です。 :) – Jon

+0

@Mechaflash:ありがとう! –

4
set filename=c:\program files (x86)\somewhere 
... 
for /f "USEBACKQ delims==" %%i in ("%filename%") do echo %%i 

USEBACKQあなたがパスを二重引用符を使用することができますスペースで

関連する問題