无忧启动论坛

标题: for命令中怎样处理带空格的目录名 [打印本页]

作者: xiao75918    时间: 2023-11-28 19:26
标题: for命令中怎样处理带空格的目录名
本帖最后由 xiao75918 于 2023-11-29 07:51 编辑

批处理中目录名称CorelDRAW Graphics Suite X7被分成了3段,%%i路径不完整,复制不了文件,而单独用if一条条去查找复制却可以。
for命令处应该如何修改?

@echo off
set "filev5=TRW_DesignWizard_v5Pro.gms"
set "path1=%USERPROFILE%\AppData\Roaming\Corel\CorelDRAW Graphics Suite X7\Draw\GMS"
set "path2=%USERPROFILE%\AppData\Roaming\Corel\CorelDRAW Graphics Suite X8\Draw\GMS"
set "path3=%USERPROFILE%\AppData\Roaming\Corel\CorelDRAW Graphics Suite 2017\Draw\GMS"
set "path4=%USERPROFILE%\AppData\Roaming\Corel\CorelDRAW Graphics Suite 2018\Draw\GMS"
set "path5=%USERPROFILE%\AppData\Roaming\Corel\CorelDRAW Graphics Suite 2019\Draw\GMS"
set "path6=%USERPROFILE%\AppData\Roaming\Corel\CorelDRAW Graphics Suite 2020\Draw\GMS"
set "path7=%USERPROFILE%\AppData\Roaming\Corel\CorelDRAW Graphics Suite 2021\Draw\GMS"
set "path8=%USERPROFILE%\AppData\Roaming\Corel\CorelDRAW Graphics Suite 2022\Draw\GMS"
set "path9=%USERPROFILE%\AppData\Roaming\Corel\CorelDRAW Technical Suite X7\Draw\GMS"
set "path10=%USERPROFILE%\AppData\Roaming\Corel\CorelDRAW Technical Suite X8\Draw\GMS"
set "path11=%USERPROFILE%\AppData\Roaming\Corel\CorelDRAW Technical Suite 2017\Draw\GMS"
set "path12=%USERPROFILE%\AppData\Roaming\Corel\CorelDRAW Technical Suite 2018\Draw\GMS"
set "path13=%USERPROFILE%\AppData\Roaming\Corel\CorelDRAW Technical Suite 2019\Draw\GMS"
set "path14=%USERPROFILE%\AppData\Roaming\Corel\CorelDRAW Technical Suite 2020\Draw\GMS"
set "path15=%USERPROFILE%\AppData\Roaming\Corel\CorelDRAW Technical Suite 2021\Draw\GMS"
set "path16=%USERPROFILE%\AppData\Roaming\Corel\CorelDRAW Technical Suite 2022\Draw\GMS"
set "allPaths=%path1% %path2% %path3% %path4% %path5% %path6% %path7% %path8% %path9% %path10% %path11% %path12% %path13% %path14% %path15% %path16%"

for %%i in (%allPaths%) do (
    if exist "%%i\%filev5%" (
        xcopy /E /I /Y "%cd%\tools\TRW\%filev5%" "%%i\"
    )
)

pause >nul
exit /b


用下面命令可以复制文件。
if exist "%path1%\%filev5%" xcopy /e /i /y "%cd%\tools\TRW\%filev5%" "%path1%\"
if exist "%path2%\%filev5%" xcopy /e /i /y "%cd%\tools\TRW\%filev5%" "%path2%\"
if exist "%path3%\%filev5%" xcopy /e /i /y "%cd%\tools\TRW\%filev5%" "%path3%\"
if exist "%path4%\%filev5%" xcopy /e /i /y "%cd%\tools\TRW\%filev5%" "%path4%\"

已解决,用双引号而不用双%号。
@echo off
set "filev5=TRW_DesignWizard_v5Pro.gms"
set "path1=%USERPROFILE%\AppData\Roaming\Corel\CorelDRAW Graphics"
set "path2=%USERPROFILE%\AppData\Roaming\Corel\CorelDRAW Technical"
for %%i in ("Suite X7" "Suite X8" "Suite 2017" "Suite 2018" "Suite 2019" "Suite 2020" "Suite 2021" "Suite 2022") do (
    if exist "%path1% %%~i\Draw\GMS\%filev5%" xcopy /E /I /Y "%cd%\tools\TRW\%filev5%" "%path1% %%~i\Draw\GMS"
    if exist "%path2% %%~i\Draw\GMS\%filev5%" xcopy /E /I /Y "%cd%\tools\TRW\%filev5%" "%path2% %%~i\Draw\GMS"
)

echo 文件复制完成按任意键关闭退出
pause >nul
exit /b




作者: szwp    时间: 2023-11-28 19:49
共同部分太多了,提取出来最后处理
作者: szwp    时间: 2023-11-28 19:53
感觉x7前面不需要set在path里
作者: nathan6498    时间: 2023-11-28 19:55
学习学习
作者: xiao75918    时间: 2023-11-29 07:50
已解决,不用双%号,而用双引号
@echo off
set "filev5=TRW_DesignWizard_v5Pro.gms"
set "path1=%USERPROFILE%\AppData\Roaming\Corel\CorelDRAW Graphics"
set "path2=%USERPROFILE%\AppData\Roaming\Corel\CorelDRAW Technical"
for %%i in ("Suite X7" "Suite X8" "Suite 2017" "Suite 2018" "Suite 2019" "Suite 2020" "Suite 2021" "Suite 2022") do (
    if exist "%path1% %%~i\Draw\GMS\%filev5%" xcopy /E /I /Y "%cd%\tools\TRW\%filev5%" "%path1% %%~i\Draw\GMS"
    if exist "%path2% %%~i\Draw\GMS\%filev5%" xcopy /E /I /Y "%cd%\tools\TRW\%filev5%" "%path2% %%~i\Draw\GMS"
)

echo 文件复制完成按任意键关闭退出
pause >nul
exit /b

作者: w766198    时间: 2023-12-6 11:20
很不错 学习学习了
作者: yyz2191958    时间: 2023-12-6 11:26
恭喜恭喜问题解决
作者: 无犹启动    时间: 2024-2-6 18:03
学习学习
作者: yyz2191958    时间: 2024-2-8 20:07
恭喜恭喜问题解决
作者: zyq137605848    时间: 2024-2-10 10:33
挺好
作者: yinchilang1    时间: 2024-2-12 07:18
谢谢分享




欢迎光临 无忧启动论坛 (http://wuyou.net/) Powered by Discuz! X3.3