Batch file to copy Users folder doesn't work, pls help!

Rafael Mestdag

Reputable
Mar 25, 2014
1,442
1
5,460
I'm using this sintax in a .bat file to make the copy process faster and easier:

ROBOCOPY "C:\Users\UserName" "C:\Backup\UserName" /mir


But I get an error, a cmd window flashes and I can't even see what it says.

What am i doing wrong?
 
Solution
I think this is perhaps a case of a little bit of knowledge being a dangerous thing!

The /XF option excludes specific files, but you need to specify the filenames (for your example "/XF NTUSER.DAT"). My apologies if that wasn't clear, I did assume you were familiar with the various options and how to use them given that you were already using the /MIR switch.

For future, if you type "robocopy /?" you'll get the list of options and how the syntax for how to use them.

I think the last suggestion will work, but you need to understand what it does. I did explain it:
You could also forget trying to mirror the top level of the user's folder, and create separate lines in your batch job for the particular folders you want to keep...


Why are you trying to do this?
There are a multitude of FREE tools that will do all manner of backups. On demand or on a schedule.


But...your cmd issue is probably not running it from an admin account.
 
Open a CMD window and copy/paste the command in, and run it from there. Then you'll get to see your error message.

Very possibly a permissions issue. Or you've mistyped your username. Or the destination folder doesn't exist.
The error message should tell you.
 


It says the NTUSER.DAT file is being used by another process.

Also, when I try to use the XCOPY command a permission error comes up about this same file.

How do I get around it?
 
NTUSER.dat is basically the user's copy of the registry. It **might** still copy fine if you load the CMD as an administrator. A better alternative is to use the /XF switch (in robocopy) to exclude that file. It'll only really be useful on that specific computer anyway. So (assuming you're interested in backing up important files rather than user settings/environment), there's no real reason to back it up anyway.

You could also forget trying to mirror the top level of the user's folder, and create separate lines in your batch job for the particular folders you want to keep (Documents, Downloads, Music, Pictures, etc). In the one batch file, you can just copy-paste your current robocopy task multiple times for each subfolder. It'll just work through them one at a time.

For example:
ROBOCOPY "C:\Users\UserName\documents" "C:\Backup\UserName\documents" /mir
ROBOCOPY "C:\Users\UserName\downloads" "C:\Backup\UserName\downloads" /mir
etc
 


Thank you, well, more or less, lol, using these lines on the batch file only copied the Documents folder(I want to backup my savegames) but it didn't copy the "C:\Users\UserName\AppData\Local" folder saying in the cmd window that it couldn't resolve the name of the file(I couldn't tell which file it was referring to).

Also, as I used the /XF switch after the /mir one, it simply deleted all the games I had in the end folder :-(.

Thanks anyway, the /XF switch was unnecessary in this case, I should've asked you what it does.

Also, I now can't delete the Documents folder the batch file created for some reason.
 
I think this is perhaps a case of a little bit of knowledge being a dangerous thing!

The /XF option excludes specific files, but you need to specify the filenames (for your example "/XF NTUSER.DAT"). My apologies if that wasn't clear, I did assume you were familiar with the various options and how to use them given that you were already using the /MIR switch.

For future, if you type "robocopy /?" you'll get the list of options and how the syntax for how to use them.

I think the last suggestion will work, but you need to understand what it does. I did explain it:
You could also forget trying to mirror the top level of the user's folder, and create separate lines in your batch job for the particular folders you want to keep (Documents, Downloads, Music, Pictures, etc)
I don't know what folders you want to keep. You need to look at them and decide what you want.

If you do it that way it won't copy the \AppData folder unless you tell it to. AppData is a hidden folder that's used as a dump for all sorts of things, like offline cache for Outlook, Google Chrome cache. It's not really the sort of thing you'd usually "back up" because it's often system and application specific. Do you actually need anything in there? Like I said above, just limit your backup to the folders that actually contain important data.
 
Solution