与目录名称的批处理问题

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

C:\ ProgramFiles(x86)\ abc \ def \ example.bat→所有任务都正确完成

C:\ Program Files(x86)\ abc \ def \ example.bat→错误行为

必须发生什么变化?

{ 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 

批处理脚本的新版本:

 @echo off set "target=%cd%\output_decrypted" for %%F in ("%~dp0..\*.wgm") do ( set "file=%%~nxF" move "%%F" "%cd%" >nul goto :next ) :next if not exist "%target%\" md "%target%" if not exist "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 2>nul 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