Why Can't I Delete a File I Created with Win XP?
Tom Pacheco
tomslists at netp.org
Sat Dec 5 23:13:11 EST 2009
W. eWatson wrote:
> I'm trying to store analytic data in a folder called Analysis. If the
> user doesn't have the folder, I make one for him, and then write a txt
> file into it. In this case a histogram of values, x and frequency.
> However, it appears that I made a mistake somewhere and cannot delete
> it using the Win XP delete. Here's the code that determines if
> Analysis exists, and whether to create it.
>
> print "Path for Histogram", self.current_path
> s = self.current_path
> s = "Analysis"
> s = os.path.join("Analysis",s)
> print "s joined ",s <------------- debug print
> if not os.path.exists("Analysis"):
> os.mkdir("Analysis")
> f = file( s, "wb")
> if not f:
> self.LogError( "Histogram file creation error 1" )
> return False
>
> In writing the code to handle all of this, I forgot to write the txt
> folder to the file, nor did I close it. It was someone else's code,
> and I got caught up in the creation of Analysis. Here's what XP tells
> me when I try to delete the folder.
>
> Very funny. I just tried it to get the content of the msg, and XP
> deleted it. Let me recreate it and try again. OK, here it is:
>
> Error Deleting Folder or File.
> Cannot delete Analysis: It is being used by another person or program.
> Close programs that might be using it and try again.
>
> There is no file created, just the folders Analysis\Analysis. One too
> many. The second Analysis shows as an icon for a file of size 0KB.
>
> I printed with the debug print above:
> Path for Histogram Events\v20070206_055012.06.dat
> s joined Analysis\Analysis
> Analysis\Analysis should only be Analysis.
noticed your assigning the same variable twice
-------------------------------
s = self.current_path
s = "Analysis"
-------------------------------
if you are expecting
Analysis\Events\v20070206_055012.06.dat
delete the second line
as others have said if you can not delete the file if must still be open.
why are you talking about deleting a file but only show code for opening it?
More information about the Python-list
mailing list