is a file open ?

John Machin sjmachin at lexicon.net
Thu Jul 21 13:13:53 CEST 2005


luis wrote:
> John Machin wrote:
> 
>> Daniel Dittmar wrote:
>>
>>> luis wrote:
>>>
>>>> for root, dirs, files in os.walk(path):
>>>>    for file in files:
>>>>       # ¿ is opened ?
>>>
>>>
>>>
>>>
>>> On Linux and some other Unixes, you can probably read the /proc 
>>> filesystem.
>>>
>>> On Windows, you'll probably get the quickest result by running 
>>> handle.exe (http://www.sysinternals.com/Utilities/Handle.html).
>>>
>>> Either way, the information you'll get is restricted by your 
>>> permissions.
>>>
>>> Either information will get stale really fast, so it's not suitable 
>>> if your task is something like 'can I backup this directory or is 
>>> someone writing to a file?'
>>
>>
>>
>> If that's what the OP had in mind, the question might have been better 
>> phrased as "given the path to a file, how can I tell if it is 
>> currently opened by another process/thread", and better directed to 
>> OS-specifc newsgroup(s).
>>
> there is a specific python function ?

If you mean "is there a Python function that given a filename, returns 
an indication of whether that file has been opened by another 
process/thread, portably across different operating systems?" then the 
answer is NO. This is what I meant by "the question might have been ... 
better directed to OS-specifc newsgroup(s)". That is what you should 
have inferred from Daniel's reply "On Linux ... probably ... On Windows 
... probably...".

If you mean something else, you might like to try rephrasing your question.



More information about the Python-list mailing list