The following for you to share a Python wildcard file deletion of the instance, has a good reference value, I hope to help you. Come and see it together.
#-*-Coding:utf-8-*-"" "Use wildcards to get all files, or to operate. "" "Import globimport osdef files (curr_dir = '. ', ext = ' *.exe '):" "" in the current directory the file "" "For I in Glob.glob (Os.path.join (curr_dir , ext)): Yield idef all_files (rootdir, ext): "" "The File" "" in the current directory and subdirectories "" for name in Os.listdir (ROOTDIR): If Os.path.isdir (Os.path.join (RootDir, name)): Try:for i in All_files (Os.path.join (RootDir, name), ext): Yield I Except:pass for I in Files (rootdir, ext): Yield idef remove_files (rootdir, ext, show = False): "" "Delete RootDir Compliant files in directory "" "For I in Files (rootdir, ext): If Show:print i os.remove (i) def remove_all_files (RootDir, ext, sho W = False): "" "Delete files conforming under RootDir directory and subdirectories" "For I in All_files (RootDir, ext): If Show:print i os.remove (i) If _ _name__ = = ' __main__ ': remove_all_files ('. ', ' *.o ', show = True) # remove_all_files ('. ', ' *.exe ', show = True) remove_f Iles ('. ', ' *.exe ', show = True) # for I in Files ('. ', ' *.c '): # Print I