简体   繁体   中英

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.

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?

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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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