How can I delete a specific number of files using python (version 2.5)?

I would like to remove two files from a folder at the end of my script. Do I need to create a function that is responsible for deleting these two specific files? I would like to know in detail how to use os.remove (if that's what I should be using) correctly. These two files will always be discarded when my script finishes (which packs a number of files together in zip format). Thank you in advance.

0


source to share


3 answers


Just call os.remove("path/to/file")

. For example, to delete a file .emacs

, call

os.remove(".emacs")

      



The path must be str

that specifies the path to the file. It can be relative or absolute.

-1


source


Sounds like what you really want is a temporary file: http://docs.python.org/library/tempfile.html



+4


source


It is perfectly acceptable to have a cleanup () function that you call at the end of your script that will call "os.remove ()" on your files.

0


source







All Articles