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

I am trying to create a batch file to create a network folder based on computer name and then copy the desktop, My Documents, Favorites from each profile to that share. So destination should be something like this: \\server\share\computername\profile name\Mydocuments, etc.

I can create the computername dir. but nothing copies. I have tried this....

@echo off
md \\servername\sharename\profile backups\%computername%
cd C:\Documents and Settings
xCopy "\%%\Desktop" \\servername\sharename\profile backups\%computername% "%computername%\%%\*.*" 

I have tried a few different methods but can never get them to copy to the share.. it needs to read the variable computername so i dont have to manually type it. Please help

share|improve this question
I also need it t read the variable userprofile name – Layton Jun 13 '13 at 17:54

You seem to be missing some variable names.

In the code supplied: Replace the first %% with %homepath%, and replace the second one with %username%

Since %homepath% includes the "C:\documents and settings\" part, you don't need to change to that directory first.

Also encapsulate any paths that contain spaces (or potentially contain spaces) with quotes.

Lastly, consider using use XCopy's switches to copy the assigned permissions as well.

@echo off
md "\\servername\sharename\profile backups\%computername%"
xcopy "\%homepath%\Desktop" \\servername\sharename\profile backups\%computername% "%computername%\%username%\" /O /X /E /H /K
share|improve this answer
Okay that helped however I need the script to copy and create each profile dir. The %username% argument only copies the logged on user. – Layton Jun 13 '13 at 18:46
Then you'll need to expand the script to include a loop, which iterates though a list of profiles. Getting that list can also be scripted by taking the info from a directory listing which contains all the profiles. Based on that, you'd probably be better off aiming to do this in PowerShell (or VBS). – Ƭᴇcʜιᴇ007 Jun 13 '13 at 20:28

You must log in to answer this question.

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