When the FOR loop in my backup script uses a double-quoted input parameter ("Default User"), I get an "invalid number of parameters" error at the xcopy command line unless I enclose it with an extra pair of double-quotes. The other commands work OK without the extra quotes. Can someone explain why xcopy behaves this way, and if there is a workaround that avoids the extra quotes? Thanks.
@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