My goal is to know if a file is locked by another process or not, even if I don’t have access to that file!
So to be more clear, let’s say I’m opening the file using python’s built-in open() with 'wb' switch (for writing). open() will throw IOError with errno 13 (EACCES) if:
- the user does not have permission to the file or
- the file is locked by another process
How can I detect case (2) here?
(My target platform is Windows)
You can use
os.accessfor checking your access permission. If access permissions are good, then it has to be the second case.