![如果父文件夹名称中有空格,批处理脚本将无法正常工作](https://linux22.com/image/1536160/%E5%A6%82%E6%9E%9C%E7%88%B6%E6%96%87%E4%BB%B6%E5%A4%B9%E5%90%8D%E7%A7%B0%E4%B8%AD%E6%9C%89%E7%A9%BA%E6%A0%BC%EF%BC%8C%E6%89%B9%E5%A4%84%E7%90%86%E8%84%9A%E6%9C%AC%E5%B0%86%E6%97%A0%E6%B3%95%E6%AD%A3%E5%B8%B8%E5%B7%A5%E4%BD%9C.png)
我注意到,如果文件夹名称中有空格,我的批处理脚本就无法正常工作:
C:\ProgramFiles(x86)\abc\def\example.bat → 所有任务均正确完成
C:\Program Files (x86)\abc\def\example.bat → 错误行为
必须发生什么改变?
@echo off
for %%F in ("%~dp0..\*.wgm") do (
set "file=%%~nxF"
move "%%F" "%cd%" >nul
goto :next
)
:next
if not exist %cd%\output md output
if not exist %cd%\temp md temp
echo File "%file%" was moved from "%~dp0..\" to "%cd%" && move "*.wgm" "%cd%\"
for /d %%i in ("%cd%\") do ( cd "%%i" ) && for %%i in (*.wgm) do tool.exe *.wgm "%%~ni".dat "643054977005802"
move "%cd%\*.wgm" temp\
move "%cd%\*.dat" output\
if exist %~dp0..\*.wgm call example.bat
if not exist %~dp0..\*.wgm goto :last
:last
for /r %%x in (*.dat) do ren "%%x" *.wgm
move "%cd%\temp\*.wgm" %~dp0..\ && rmdir /s /q "%cd%\temp"
exit