当我的备份脚本中的FOR循环使用双引号输入参数(“默认用户”)时,我在xcopy命令行中得到“参数数量无效”错误,除非我用一对额外的双重括起来-quotes。其他命令工作正常,没有额外的引号。有人可以解释为什么xcopy会以这种方式运行,并且如果有一种解决方法可以避免额外的报价?感谢。
@echo off
setlocal
set drive=O:\Backups\test
set backupcmd=xcopy /s /c /d /e /i /r /y
if exist "c:\users" goto startvis7
if exist "c:\documents and settings\" goto startxp
:startxp
for %%a in ("Default User" Owner) do (
if exist "c:\documents and settings\%%a" (
echo ### Backing up desktop for %%a...
%backupcmd% ""c:\documents and settings\%%a\desktop"" ""%drive%\%%a\desktop""
) else (echo ### Account %%a not found.)
)
goto eof
:startvis7
for %%a in ("Default User" Owner) do (
if exist "c:\users\%%a" (
echo ### Backing up desktop for %%a...
%backupcmd% ""c:\users\%%a\desktop"" ""%drive%\%%a\desktop""
) else (echo ### Account %%a not found.)
)
:eof
echo Backup Complete!
@pause
endlocal
答案 0 :(得分:2)
你在%%a
中遇到问题
%backupcmd% ""c:\users\%%a\desktop"" ""%drive%\%%a\desktop""
它也可以包含引号,因此您的字符串可能看起来像
""c:\users\"Default User"\desktop""
您可以使用%%~a
语法,它会删除周围的引号,然后您应该可以使用
%backupcmd% "c:\users\%%~a\desktop" "%drive%\%%~a\desktop"