windows 错误的“共享违规”Xcopy 错误消息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20154980/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
False 'Sharing Violation' Xcopy error message
提问by Fractal
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'.
我正在运行批处理脚本(在计算机 A 上)。该脚本将多个文件从另一台计算机(计算机 B)复制到计算机 A。运行批处理脚本时,它报告由于“共享冲突”而无法将某些文件从计算机 B 复制到其自己的目录。
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).
通过阅读其他 stackoverflow 页面,我发现当另一个程序将文件锁定(另一个程序当前正在使用/访问该文件)时会发生这种情况。但是,我可以转到计算机 B 并删除计算机 A 声称已锁定的文件(由于共享冲突)。
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.
我能想象的唯一可能发生的事情是计算机 A 上的批处理脚本在较早的命令期间(以某种方式)锁定了文件,而这个较早的命令是什么锁定了文件?但我虽然批处理脚本命令串行运行,除非另有说明。
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.
有没有人遇到过这个问题?大约一两周前,脚本将成功复制而不会共享违规行为。脚本中没有发生任何变化。
回答by Fractal
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
我正在将文件从计算机 B 复制到计算机 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].
我认为发生共享冲突是因为计算机 B 不允许我复制这些文件 [存储在其硬盘上]。
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.
实际上,计算机A(计算机复制到的)上的目录有我无法覆盖的文件。这就是我收到共享违规的原因。
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.
计算机 A 上的目录中的一个文件是一个可执行任务,我认为它已被杀死 (taskkill)。但是,这个可执行文件在 taskkill(实际上由于某种原因没有在任务管理器中列出)过程中被忽略了,并且这个程序仍在运行(文件正在使用中)。因此,当我尝试覆盖该文件时,xcopy 被拒绝访问以覆盖此文件/可执行文件,从而导致共享冲突。
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.
我的印象是,如果计算机 B 上的文件不允许复制发生,共享冲突只会在 xcopy 期间发生。
回答by Thiago Burgos
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.
大多数情况下,您遇到此问题是因为另一个可执行程序 (exe) 以某种方式使用了您要复制的文件。只需使用任务管理器终止程序,副本就可以工作。
回答by Andrej
The /C
switch solved the issue for me. Xcopy then skipped the files that were opened by other programms and went on.
该/C
开关解决了这个问题对我来说。Xcopy 然后跳过其他程序打开的文件并继续。
回答by Bob
I ran into the same issue with xcopy in a batch file and discovered that the file causing the sharing violation had the Read Only attribute set. Removing the Read Only attribute allowed the file to be copied.
我在批处理文件中遇到了与 xcopy 相同的问题,并发现导致共享冲突的文件设置了只读属性。删除只读属性允许复制文件。
I should note that I was already using the /R switch with xcopy to allow overwriting read only files. I've also discovered that the file was already in the destination folder with the Read Only attribute set, and it appears that Read Only has been reset on the target file after it was xcopied successfully. I still need to investigate this further. The /K switch may prevent this.
我应该注意到我已经在 xcopy 中使用了 /R 开关来允许覆盖只读文件。我还发现该文件已经在目标文件夹中,并设置了只读属性,并且在成功复制后,目标文件上的只读似乎已被重置。我仍然需要进一步调查。/K 开关可能会阻止这种情况。
Also worth noting is that my batch file contained a series of xcopy statements. The sharing violation crashed the first line, but allowed the batch file to continue to subsequent xcopy lines. The error had been occurring unnoticed for quite some time, as the sharing violation message had scrolled off the screen. I could also try using the /C switch to continue copying even if errors occur.
另外值得注意的是,我的批处理文件包含一系列 xcopy 语句。共享冲突使第一行崩溃,但允许批处理文件继续到后续的 xcopy 行。由于共享违规消息已滚出屏幕,因此该错误已在很长一段时间内未被注意到。即使发生错误,我也可以尝试使用 /C 开关继续复制。
I hope this might help others that run into this issue.
我希望这可以帮助遇到此问题的其他人。
回答by Constantinos Makassikis
Sometimes a file/directory can be temporarily unavailable/locked by another process. If your batch program tries to copy at that moment it will result in a "unknown error/shared violation".
有时文件/目录可能暂时不可用/被另一个进程锁定。如果您的批处理程序在那一刻尝试复制,则会导致“未知错误/共享冲突”。
Using robocopyinstead of "xcopy/copy" may be more relevant in that case, as it does not fail immediately, but retries a couple of times before failing.
在这种情况下,使用robocopy而不是“xcopy/copy”可能更相关,因为它不会立即失败,而是在失败之前重试几次。
回答by Pete B.
For me this occurred when I was attempting to copy a war file into a tomcat directory. I kept checking to see that, indeed, tomcat was stopped. The issue was I had the war file open in 7zip as I was examining the contents. I closed 7zip and the issues when away.
对我来说,这发生在我试图将一个 war 文件复制到 tomcat 目录中时。我一直在检查,确实,tomcat 被停止了。问题是我在检查内容时在 7zip 中打开了 war 文件。我在离开时关闭了 7zip 和问题。
Obvious now, not so much when this was occurring.
现在很明显,在发生这种情况时并不那么明显。
回答by Tomá? Na'vi Koválik
I ran into the same problem... The problematic file was an excel sheet. The cause of the problem was, that file I wanted to copy was opened by my colleague. It's good to mention that I am copying data from my station to the shared folder. So xcopy can't override it.
我遇到了同样的问题......有问题的文件是一个excel表。问题的原因是,我要复制的文件被我的同事打开了。值得一提的是,我正在将数据从我的工作站复制到共享文件夹。所以 xcopy 不能覆盖它。
回答by Bardi
I had "Access denied"that went away if I ran the .BAT file as Administrator.
我有“拒绝访问”那走了,如果我跑了.BAT文件管理器。
Some ACT! files were held open by background SQL and gave "Sharing violation"message for each file. I killed the background SQL processes and the files copied with no issues.
一些行为!文件由后台 SQL 保持打开状态,并为每个文件提供“共享冲突”消息。我杀死了后台 SQL 进程,复制的文件没有问题。
Not sure if robocopy would have worked; I'm still using Xcopy at this point.
不确定 robocopy 是否有效;此时我仍在使用 Xcopy。