每建议我添加了/ad
仅返回目录,但仍然收到提示。提示表明它想知道是否要创建文件或目录。
如何在批处理脚本中自动回答问题?
这是提示:
Does \\server\tf\POL-5TVK5J1\Administrator\Desktop specify a file name or directory name on the target (F = file, D = directory)?
这是我的脚本:
@echo off
md "\\my server\tf\%computername%"
cd documents and settings
for /f %%u in ('dir /b /ad') do xcopy /s "c:\Documents and Settings\%%u\Desktop" "\\my server\tf\%computername%\%%u\Desktop" /D /R
for /f %%u in ('dir /b /ad') do xcopy /s "c:\Documents and Settings\%%u\Favorites" "\\my server\tf\%computername%\%%u\Favorites" /D /R
for /f %%u in ('dir /b /ad') do xcopy /s "c:\Documents and Settings\%%u\My Documents" "\\my server\tf\%computername%\%%u\My Documents" /D /R
for /f %%u in ('dir /b /ad') do xcopy /s "c:\Documents and Settings\%%u\Personal" "\\my server\tf\%computername%\%%u\Personal" /D /R
for /f %%u in ('dir /b /ad') do xcopy /s "c:\Documents and Settings\%%u\local settings\application data\Microsoft\Outlook" "\\my server\tf\%computername%\%%u\Outlook" /D /R
答案1
xcopy 的这个参数应该有帮助:
/I If destination does not exist and copying more than one file,
assumes that destination must be a directory.
答案2
忘记了最终目标路径中的斜线"\\my server\tf\%computername%\%%u\Desktop\"
for /f %%u in ('dir /b /ad') do xcopy /s "c:\Documents and Settings\%%u\Desktop" "\\my server\tf\%computername%\%%u\Desktop\" /D /R