如果父文件夹名称中有空格,批处理脚本将无法正常工作

如果父文件夹名称中有空格,批处理脚本将无法正常工作

我注意到,如果文件夹名称中有空格,我的批处理脚本就无法正常工作:

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

相关内容