Deleting files with wildcards

Alex Martelli alex at magenta.com
Wed Jul 26 15:04:06 EDT 2000


"Manfred Pisecky" <pisecky at tttech.com> wrote in message
news:397f046d.193858654 at news.atnet.at...
> Hello everyone!
>
> I have to delete a bundle of files, e.g. *.txt in a portable way (it
> must work for Linux and NT).
>
> I use Python 1.5.2. and have not found a way to either delete files
> with wildcards or to read the directory content (and do it file by
> file).
>
> Is there a portable way in 1.5.2 ?

os.listdir(path) will portably return the list of all files in
the path, and os.unlink can be used to delete one or more of
them (or, os.remove, too).  os.path.walk is also handy if you
need to iterate on a whole subdirectory tree.


Alex






More information about the Python-list mailing list