简体   繁体   English

使用python在Windows上复制锁定的dbf文件

[英]Copy locked dbf file on windows using python

Well, almost everything is in title.好吧,几乎所有内容都在标题中。 I have a dbf file which I would like to copy even if it is locked (edited) by another program like DBU.我有一个 dbf 文件,即使它被另一个程序(如 DBU)锁定(编辑),我也想复制它。

If I try to open it or copy with shutil.copy I get如果我尝试打开它或使用 shutil.copy 进行复制,我会得到

>>> f = open('test.dbf', 'rb')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IOError: [Errno 13] Permission denied: 'test.dbf'

I know that it is locked on windows level because I am unable to copy it witch batch or with windows explorer.我知道它被锁定在 Windows 级别,因为我无法批量复制它或使用 Windows 资源管理器复制它。 But is there any method to copy such a file?但是有什么方法可以复制这样的文件吗?

In general, you can't.一般来说,你不能。 Even if you were to circumvent the locking mechanism, another process might be in the middle of writing to the file, and the snapshot you would take may be in an inconsistent state.即使您要绕过锁定机制,另一个进程可能正在写入文件,并且您拍摄的快照可能处于不一致状态。

Depending on your use case, Volume Shadow Copy might be of relevance.根据您的用例,卷影复制可能具有相关性。

There is a tool from Joakim Schicht that copies any locked file. Joakim Schicht有一个工具可以复制任何锁定的文件。 The only issue is that some AV tag it as malicious, when it is not.唯一的问题是某些 AV 将其标记为恶意,而实际上并非如此。 Depending on your use case, this can be a solution.根据您的用例,这可能是一个解决方案。

https://github.com/jschicht/RawCopy https://github.com/jschicht/RawCopy

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM