为批处理文件添加空间

时间:2013-03-19 20:09:53

标签: batch-file

我的批处理如何在路径示例中处理空间:

C:\ Documents and Settings \ K \ Desktop \ New Folder

@echo off
pushd "%~dp0"
IF EXIST "%1" GOTO DECODE_INDIVIDUAL

:DECODE_MULTIPLE
xcopy /s /c /d /e /h /i /r /y "%cd%\encoded" "%cd%\decoded\"
dir "%cd%\decoded\*.php"  /A:-D /B /O:N /S >> "%cd%\filelist.txt"

@echo on
for /F %%e in ("%cd%\filelist.txt") do ( copy "%%e" "bin\file.php" && "php.exe" "bin\decoder.php" "bin\file.php" && move "bin\file.php" "%%e" && del "bin\file.php")
del /Q "%cd%\filelist.txt"
GOTO DECODE_END

:DECODE_INDIVIDUAL
@echo on
"php.exe" "%cd%\bin\decoder.php" "%1"

:DECODE_END

2 个答案:

答案 0 :(得分:1)

for /F "USEBACKQ delims=" %%e in .....

答案 1 :(得分:0)

如果路径或文件名中有空格,则必须将分隔符设置为空:

for /F "usebackqdelims=" %%e in ("%cd%\filelist.txt") do ( copy "%%~e" "bin\file.php" && "php.exe" "bin\decoder.php" "bin\file.php" && move "bin\file.php" "%%~e" && del "bin\file.php")

您应该使用比%%~z更好的%%z~会删除其他双引号。

根据Peter Wright的回答编辑。