Python Wildcard Delete File

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.