Check file is locked?

Nobody nobody at nowhere.com
Wed Jul 8 13:25:49 EDT 2009


On Tue, 07 Jul 2009 21:31:12 -0700, Rajat 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.

Windows doesn't allow you to delete (or rename) open files. It's up to the
application as to whether it keeps the file open or closes it once it has
been read.

> Please suggest if this is fine.

If you can't delete the file, then you can't delete it. You shouldn't be
trying to kill off applications so that you can delete the file. Just do
what other Windows programs (including those which are part of Windows)
do: display a dialog telling the user to close the application then try
again.




More information about the Python-list mailing list