Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Per suggestion I added /ad to return only dirs, but continue to get prompted. The prompt suggests it wants to know whether to create a file or directory.

How do I automate the answer in a batch script?

This is the prompt:

Does \\server\tf\POL-5TVK5J1\Administrator\Desktop specify a file name or directory name on the target (F = file, D = directory)?

Here is my script:

@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
share|improve this question
Per what suggestion? I've added the link, but next time you should remember to do so, so as not to confuse people who don't know what you might be referring to. – Karan Jun 18 '13 at 18:54
forgotten slash in end destination path "\\my server\tf\%computername%\%%u\Desktop\" – STTR Jun 18 '13 at 19:07
up vote 5 down vote accepted

This parameter for xcopy should help:

/I    If destination does not exist and copying more than one file,
      assumes that destination must be a directory.
share|improve this answer
Hi, clear directory -> file?) – STTR Jun 18 '13 at 19:02
@STTR: I couldn't quite understand your comment. Can you ask in a different way? Since he's copying directories, /i will help the OP and automatically create directories at the destination, instead of prompting him every time. It's better to use this rather than rely on a trailing backslash. – Karan Jun 18 '13 at 19:03
THis is it! thanks! I am obviously inexperienced. Thanks so much Not sure where to add the /i so i went with the trailing backslash and it works like a charm. – Layton Jun 18 '13 at 19:27
xcopy /? says XCOPY source [destination] [options], but I don't think it cares about the order. You can add /s /d /r /i all together right after xcopy and before you specify the source and destination dirs, or at the end, as you prefer. – Karan Jun 18 '13 at 19:32

forgotten slash in end destination path "\\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

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .