Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Ok here is the scenario. I am trying to figure out a way to copy users' docs and settings (Favorites, My Documents and Desktop) to a network location as a backup for decommissioned drives. My problem is the variable of the user names %username% is only the logged in user so I have opted to export to a list but I do not know the correct way to import those names back in or create the loop. Notice I also would like my destination directory to use the same username. Please notice this is just for the desktop folder so far. Here is what I have so far:

@echo off
md "\\server\share\folder\Downloads\%computername%"
cd documents and settings
dir >> list.txt 

xcopy /s "c:\Documents and Settings\dir >> list.txt\Desktop" "\\server\share\folder\downloads\%computername%\(name from list)" /D/R
share|improve this question
    
If you are able to use Windows Easy Transfer, it affords a nice UI to individually select all the users and the particular special user folders of interest. Furthermore it zips it up nicely in a special binary file, which is convenient since you're using it as a backup and don't care about viewing the files. –  Robert Kerr Jun 17 '13 at 20:32

1 Answer 1

up vote 1 down vote accepted

why don't you loop over your users dirs with something like this?

@echo off
md "\\server\share\folder\Downloads\%computername%"
cd documents and settings

for /f %%u in ('dir /b') do (
    xcopy /s "c:\Documents and Settings\%%u\Desktop" "\\server\share\folder\downloads\%computername%\%%u" /D/R

IMHO no need to use a temp file... (unless you need it for another reason)

share|improve this answer
    
This works great thanks! however i do get a prompt asking if this is a dir or a file. How can i answer that in the script. –  Layton Jun 18 '13 at 14:08
    
dir /b /ad should return you only dirs... –  pataluc Jun 18 '13 at 14:17
    
I added that but continues the prompt. Does \\my servername\tf\POL-5TVK5J1\Administrator\Desktop specify a file name or directory name on the target (F = file, D = directory)? –  Layton Jun 18 '13 at 15:59
    
THis is as now@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 %SystemRoot%\explorer.exe "c:\Documents and Settings" %SystemRoot%\explorer.exe "\\my server\tf\%computername%" –  Layton Jun 18 '13 at 16:02
    
I added that but continues the prompt. Does \\my servername\tf\POL-5TVK5J1\Administrator\Desktop specify a file name or directory name on the target (F = file, D = directory)? Any help getting around the prompt or changes to run the script without copying locally first would be great. –  Layton Jun 18 '13 at 16:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.