Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

False 'Sharing Violation' Xcopy error message

I am running a batch script (on computer A). The script copies several files from another computer (computer B) to computer A. When the batch script is run, it reports it is unable to xcopy some files from computer B to its own directories due to 'Sharing Violations'.

By reading other stackoverflow pages, I see that this happens when another other program has the file locked up (another program is currently using/accessing the file). However, I can go onto computer B and delete the file which computer A claimed was locked (due to sharing violations).

The only thing i can imagine might be happening is that the batch script on computer A is locking up the file (somehow) during an earlier command and this earlier command is what is locking up the file? But I though batch script commands run serially unless specified otherwise.

Has anyone ever had this problem before? The script would copy successfully without sharing violations about a week or two ago. No changes have occurred in the script.

like image 653
Fractal Avatar asked Nov 22 '13 21:11

Fractal


People also ask

How do I stop xcopy asking file or directory?

Press F if you want the file or files to be copied to a file. Press D if you want the file or files to be copied to a directory. You can suppress this message by using the /i command-line option, which causes xcopy to assume that the destination is a directory if the source is more than one file or a directory.

What is the meaning of Xcopy?

XCOPY stands for extended copy, and was created as a more functional file copying utility than the copy command found in earlier operating systems.

Did Robocopy replace xcopy?

Robocopy, for "Robust File Copy", is a command-line directory and/or file replication command for Microsoft Windows. Robocopy functionally replaces Xcopy, with more options.

What is the Xcopy command in command prompt?

Copy files and/or directory trees to another folder. XCOPY is similar to the COPY command except that it has additional switches to specify both the source and destination in detail. /D:mm-dd-yyyy Copy files changed on or after the specified date.


2 Answers

After much trial and error I was able to determine why I was getting a shared violation

I was copying files from computer B to computer A

I thought the sharing violations were occurring because computer B was not allowing me to make a copy of those files [stored on its harddrive].

In actuality, the directory on computer A (computer copying to) had files which I could not write over. This is why I was getting the shared violation.

One of the files in the directory on computer A was an executable task which I thought had been killed (taskkill). However, this executable got overlooked in the taskkill (actually wasn’t listed in the task manager for some reason) process and this program was still running (the file was in use). Therefore, when I tried to overwrite the file, xcopy was denied access to overwrite this file/executable, resulting in shared violations.

I was under the impression that sharing violations would only occur during xcopy if the files on computer B would not allow the copy to occur.

like image 68
Fractal Avatar answered Oct 10 '22 11:10

Fractal


Most of the times when you have this problem is because another executable program (exe) is somehow using the files you want to copy over. Just kill the program using task manager and the copy will work.

like image 24
Thiago Burgos Avatar answered Oct 10 '22 12:10

Thiago Burgos