Check file is locked?

Dave Angel davea at ieee.org
Wed Jul 8 06:18:47 EDT 2009


Rajat wrote:
> On Jul 8, 4:57 am, Lawrence D'Oliveiro <l... at geek-
> central.gen.new_zealand> wrote:
>   
>> In message <mailman.2795.1246997268.8015.python-l... at python.org>, Christian
>>
>> Heimes wrote:
>>     
>>> By the way most operating systems don't lock a file when it's opened for
>>> reading or writing or even executed.
>>>       
>> The general conclusion seems to be that mandatory locking is more trouble
>> than it's worth.
>>     
>
> My OS is a windows XP sp3. All I'm trying to achieve is to close an
> application ( which could be a notepad, a wordpad or some other text
> editor) that have opened my file. Once the file is closed I can easily
> delete that file.
>
> I guess, if file is opened by one of that application, the file must
> be locked and so is the reason I cannot delete the file.
>
> Please suggest if this is fine.
>
>
>   
Neither Wordpad nor Notepad lock the files they have open, at least in 
my experience.  Specifically, I just tried it in XP Sp3.   I created a 
file, opened the file in one of the apps, then deleted the file before 
closing the app.

Word for Windows, on the other hand, has locked files for me in the 
past.  When I tried that one just now (on a text file, because that was 
easy), results were rather confusing.  It let me delete the file, but 
then when I tried to "save" it, it gave me a permissions error.  My 
experience with Winword has been that it's in a world of its own, best 
not messed with.  And this latest version (Office 2007 or somesuch) is 
so modern that it has removed the Help->About menu to make sure I can't 
even tell what version it is.  Next time I rebuild my system, I think 
I'll go back to Office 97.


But perhaps your question is intended to cover the general case.  You 
can get a program from sysinternals called   handle, which will list all 
the files (and other handles) opened by all the processes in the 
system.  You may be able to run that (with subprocess, or just from the 
commandline), and filter its output for the information you want.


DaveA



More information about the Python-list mailing list