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.

I am trying to write a batch file to back up my locally stored files to a network drive. Some folders are being successfully copied, but others are not; instead the destination folder is being deleted when the command is executed.

Working as expected (copies all files into destination folder):

XCOPY /Y "C:\APPS\lse_jboss-4.2.3.GA-1.1\server\default\deploy\lse_datasources-esl_sourcesdedonnees" "H:\My Documents\RESTORE\Data sources"
XCOPY /Y "%AllUsersProfile%\Desktop" "H:\My Documents\RESTORE\Desktop - Global"
XCOPY /Y "%UserProfile%\Desktop" "H:\My Documents\RESTORE\Desktop - mwa700"
XCOPY /Y "%UserProfile%\Favorites" "H:\My Documents\RESTORE\Favorites"
XCOPY /Y "%UserProfile%\Application Data\Microsoft\Templates" "H:\My Documents\RESTORE\Office templates"

Not working as expected (copies 0 files, and deletes destination folder):

XCOPY /Y "%UserProfile%\java_libraries" "H:\My Documents\RESTORE\java_libraries"
XCOPY /Y "%UserProfile%\workspaces" "H:\My Documents\RESTORE\workspace"

Are there contents or properties of either folder that could explain this behaviour?

share|improve this question
    
Xcopy is sooo 20th century. Have you considered using Robocopy? –  kinokijuf Dec 14 '11 at 15:08
    
@kinokijuf: Work computer, so installing non-standard software isn't an option. –  Matt Dec 14 '11 at 15:41
2  
Robocopy is a microsoft app that is included in the server admin pack. Your IT shop shouldn't have a problem with it: google.com/search?q=robocopy+download –  music2myear Dec 14 '11 at 15:50
add comment

2 Answers

up vote 2 down vote accepted

Yes. By default xcopy copies files only, not directories. So if your source directories only contains other subdirectories it will not copy anything. To make sure you also copy directores use the /E flag to copy directores and subdirectores (including empty ones) or /S to skip the empty directories.

xcopy /Y /E "src" "dest"

Also use /I to assume destination is a directory if more than one file is copied.

xcopy /Y /E /I "src" "dest"

For more help use

xcopy /?
share|improve this answer
add comment

Try using the dos formatted filename for the Documents and Settings, or use the %userprofile% path command variable.

The only difference between your two statements above is there are not spaces in the source in the working script, and there are spaces in the path of the non-working script.

Use the %userprofile% path command first, it's easier and supported by all MS OSes.

share|improve this answer
    
Behaviour is unchanged using this instead (commands that worked before continue to work, commands that deleted the destination folder continue to delete the destination folder). I will update my question to use this format instead, since it does eliminate a variable. –  Matt Dec 14 '11 at 15:36
    
Downvote? Why? I provided a possible answer and it turned out to be incorrect. Save the downvotes for unhelpful, not merely inaccurate answers and posts. –  music2myear Dec 14 '11 at 16:29
add comment

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.