Remove files of same type (extension)
A.A
andtherewaswater at yahoo.com
Mon Sep 24 09:38:28 EDT 2001
You can use the fnmatch module to match using dos/unix like patterns:
for eachfile in os.listdir(FolderPath):
if fnmatch.fnmatch(filename, '*.dat'):
# delete file
(Obligatory) Warning: Be careful to use the right pattern, else you
might end up deleting other files !!!
A.A.
Markus Faust wrote:
>
> Hi,
>
> I want to write a script (Windows NT) which deletes all files in a directory
> with the same extension, i.e. all .dat files.
>
> Is there something like os.remove('*.dat') or how can I achieve this goal?
>
> Thanks in advance!
> Markus
More information about the Python-list
mailing list