delete file

lamar_air lamar_air at
Tue Jul 15 17:43:02 CEST 2003

Peter Hansen <peter at> wrote in message news:<3F0EBFED.BB283660 at>...
> lamar_air wrote:
> > 
> > Peter Hansen <peter at> wrote in message news:<3F0D962E.23DA9F59 at>...
> > > "Bartolomé Sintes Marco" wrote:
> > > >
> > > > I have a program that unzip some zip files. After unzipping them,
> > > > I want to delete the zip files with os.remove, but I get this error:
> > > > OSError: [Errno 13] Permission denied: ....
> > >
> > > Close the files properly after unzipping them, perhaps?  If that
> > > doesn't help, please specify operating system, and give details
> > > on how you are unzipping.  Is it using Python's zipfile module,
> > > or some other method, and exactly how do you do it?
> > 
> > I want to be able to delete a file on my C: drive through my python
> > script.  My script writes a file. So i want to delete the file if it
> > already exists then write it.  What's the best way to do this?
> Your question is still not clear, if it's the same as the original
> question.  Please read
> for assistance in formulating your questions a little better.
> The simplest answer is that if *you* are creating the files, you
> just open them with "w" mode (as in "f = open('filename', 'w')")
> and it will automatically truncate the file if it already exists.
> Hoping that helps,
> -Peter

I am using this remove method and it works well as long as the file is
If the file doesn't exist then i get an error that the file is not
found.  I want to stay away from using
f2=open('C:\Inetpub\wwwroot\Cgi-bin\output.txt', 'w') so how can i
check if the file exists first?

More information about the Python-list mailing list