Why Can't I Delete a File I Created with Win XP?

J dreadpiratejeff at gmail.com
Sat Dec 5 20:32:01 EST 2009


On Sat, Dec 5, 2009 at 17:42, John Machin <sjmachin at lexicon.net> wrote:
> On Dec 6, 2:46 am, "W. eWatson" <wolftra... at invalid.com> wrote:
>> However, even at
>> that, why can't I delete this empty file called Analysis?
>
> Are you trying to delete the file from another command window while
> Python is paused at the interactive prompt? In any case describe how
> you are trying to delete the file. Fire up another command window, cd
> to whatever is the current working directory for your script, do a dir
> command, and copy/paste the RELEVANT parts (including all directory
> names). Please don't top-post, and before you hit the send button,
> please delete any text that is more appropriate to your memoirs than a
> problem description.

I'm no expert in Python, so YMMV and all that, but sounds like, as was
mentioned before, that the file isn't being properly closed.  I was
under the impression that the interpreter would close any open
filehandles as part of garbage collection as the script ends and the
interpreter closes out... but it's good practice to explicitly close
them in any case instead of just assuming that the interpreter or os
will do it for you... applicable to any language, not just python.

But that being said, this brings to mind a question about this...  in
*nix, when I can't do something like delete a file or directory, or
unmount a filesystem and cant find the cause, I can do an lsof and
grep for references to the file/directory in question, then work from
there to close anything that still has a lock.

Most all of the development work I've ever done (other than C++ and
VB.Net) has been done on Linux systems.  And honestly, most of my C++
stuff was written/compiled on Linux systems too... so I'm not that
experienced with developing applications on windows.  Does Windows (XP
or later) have an lsof or lsof type tool to show who/what has a lock
on a file or folder?  I've not found anything like that so far, but as
I said, I'm not much of a windows user anyway.

I'm at the point where I can actually write useful code in Python, and
not just hack my way through to a solution, so this is somethign that
would be useful for me to know.  I'm about to start work on writing a
test tool in Python 2.6 which is going to have to work with a few
filehandles, both for read and write actions, as well as socket
connections eventually.  So being able to find who has a lock on a
given file or directory if the program dies unexpectedly would be
useful.

Cheers
Jeff



-- 

Charles de Gaulle  - "The better I get to know men, the more I find
myself loving dogs." -
http://www.brainyquote.com/quotes/authors/c/charles_de_gaulle.html



More information about the Python-list mailing list