I know how to delete single files, however I am lost in my implementation of how to delete all files in a directory of one type.
Say the directory is \myfolder
I want to delete all files that are .config files, but nothing to the other ones. How would I do this?
Thanks Kindly
I would do something like the following:
It lists the files in a directory and if it's not a directory and the filename has ".config" anywhere in it, delete it. You'll either need to be in the same directory as myfolder, or give it the full path to the directory. If you need to do this recursively, I would use the os.walk function.
Here ya go:
Note also that
gen_files
can be easily rewritten to accept a tuple of patterns, sincestr.endswith
accepts a tupleUse the
glob
module: