Batch file 为批处理文件添加空间
我的批处理如何处理路径中的空间示例:Batch file 为批处理文件添加空间,batch-file,Batch File,我的批处理如何处理路径中的空间示例: C:\Documents and Settings\K\Desktop\New文件夹 @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 >&
C:\Documents and Settings\K\Desktop\New文件夹
@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
如果路径或文件名中有空格,则必须将分隔符设置为“无”:
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的答案编辑。是通过
%1
的路径还是作为%CD%
的路径?注意:将“%1”
更改为“%~1”
.C:\Documents and Settings\K\Desktop\DECODER>(复制“C:\Documents”“bin\file.php”和“php.exe”“bin\DECODER.php”“bin\file.php”&&move“bin\file.php”“C:\Documents”和&del“bin\file.php”)1个文件bin\file.php:error找不到C:\Documents and Settings\K\Desktop\DECODE R\bin\file.php
for /F "USEBACKQ delims=" %%e in .....