使用python在Windows上复制锁定的dbf文件
好吧,几乎所有内容都在标题中。我有一个 dbf 文件,即使它被 DBU 等其他程序锁定(编辑),我也想复制它。
如果我尝试打开它或使用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'
它被锁定在Windows级别,因为我无法批量或使用Windows资源管理器复制它。但是有什么方法可以复制这样的文件吗?
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.
If I try to open it or copy with shutil.copy I get
>>> 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. But is there any method to copy such a file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一般来说,你不能。即使您要规避锁定机制,另一个进程也可能正在写入文件,并且您拍摄的快照可能处于不一致的状态。
根据您的使用案例,卷影复制可能相关。
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.
Joakim Schicht 有一个工具可以复制任何锁定的文件。
唯一的问题是,有些反病毒软件将其标记为恶意软件,而实际上并非如此。
根据您的用例,这可能是一个解决方案。
https://github.com/jschicht/RawCopy
There is a tool from Joakim Schicht that copies any locked file.
The only issue is that some AV tag it as malicious, when it is not.
Depending on your use case, this can be a solution.
https://github.com/jschicht/RawCopy