xcopy deletes destination folder and copies 0 files

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?

3

3 Answers

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 /?

I don't know if this is an answer that works for you, but I used an xcopy command to copy all of a C: folder to a backup location on another disk device (call it folder E:\A). After the copy completed successfully, folder E:\A disappeared from Explorer!

By moving the device at E: to another computer, I could see that xcopy had set the S and H (System and Hidden) attributes of E:\A, causing it to vanish. These attributes had, perhaps correctly, been copied from the C:\ folder to the E:\A folder itself.

I used the attrib command to restore those two attributes, and all is now well. E:\A contains the folders and files that were copied from C: .

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.

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like