XCopy encounters a sharing violation, how to handle

I'm using xcopy for copying large bundles of files. One thing I particularly like about xcopy is the /F switch which shows all source and destination files, paths included, something like:

xcopy /E /Y /F D:\Temp_Folder\test_origin\* D:\Temp_Folder\test_dest\
D:\Temp\origin\B_Normal\blabla.txt -> D:\Temp\dest\B_Normal\blabla.txt
D:\Temp\origin\B_Normal\B.A\normal.txt -> D:\Temp\dest\B_Normal\B.A\normal.txt
D:\Temp\origin\B_Normal\B.B\drawing.bmp -> D:\Temp\dest\B_Normal\B.B\drawing.bmp
D:\Temp\origin\C_Fill_with_empty\empty.bmp -> D:\Temp\dest\C_Fill_with_empty\empty.bmp
D:\Temp\origin\C_Fill_with_empty\empty.txt -> D:\Temp\dest\C_Fill_with_empty\empty.txt
5 File(s) copied

However there seem to be some issues:

D:\Temp\origin>tree /F /A
...
D:.
+---A_Empty
+---B_Normal
| | blabla.txt
| |
| +---B.A
| | normal.txt
| |
| \---B.B
| Drawing.bmp
|
\---C_Fill_with_empty | empty.bmp | empty.txt | \---empty

As you can see, the directories D:\Temp\origin\A_Empty\ and D:\Temp\origin\C_Fill_with_empty\empty\ seem not having been copied (empty files seem to be copied, not empty directories).

This however is not true: in the destination folder, the directories A_empty and C_Fill_with_empty\empty are there, but the /F switch only showed the files which were copied, so the copy of empty directories is done, but not shown. (In my original post, I thought the empty directories were not copied)

Most important, I don't understand the meaning of the /C switch, which says

Continues copying even if errors occur.

Last night the xcopy result of a bunch copy was an error message:

\\nas\<Complicated_Directory_Tree>\<file1>.gif -> G:\<Complicated_Directory_Tree>\<file1>.gif
\\nas\<Complicated_Directory_Tree>\<file2>.gif -> G:\<Complicated_Directory_Tree>\<file2>.gif
Sharing violation

I would like to avoid this irreproducible error message, using a retry mechanism, but I don't know how the /C switch will behave: will it behave as a "Retry" or an "Ignore"? (This question has already been asked by other people, but those people received the advise to change to robocopy, but as mentioned in this StackOverflow post, also this seems not so error-prone).

Does anybody know how to force a retry mechanism?

Thanks in advance

6

1 Answer

The /E parameter copies directories and subdirectories, including empty ones. Just add that, and the problem is solved.

The /C parameter continues copying even if errors occur. That should skip any problems.

To elaborate, the /c ignores the error and continues the copy process with the next valid file.

If you want retries on errors (although not recommended) you could use a WHILE loop in the batch file for that (useful commands: IF ERRORLEVEL = and timeout). Example.

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