Python implementation deletes a specified size file under the specified directory

Source: Internet
Author: User

Import OS, sysfrom stat import *big_file_threshold = 6000L #1000000Ldict1 = {}  # dict2 = {}   # def treewalk (path): C2/>try: For    i in Os.listdir (path):      mode = Os.stat (path+ "/" +i). St_mode      if S_isdir (mode) <> True:        filename = path+ "/" +i        filesize = os.stat (filename). st_size        If filesize < big_file_threshold:          if FileSize in Dict1:                       dict2[filename] = filesize            dict2[dict1[filesize]]=filesize          else:            dict1[ FileSize] = filename               else:        treewalk (path+ "/" +i)  except Windowserror:    passdef printdict ( finaldict): For  i_size in Finaldict.values ():    print i_size for    j_name in Finaldict.keys ():      if Finaldict[j_name] = = i_size:        print J_nameos.remove (j_name)    print "\ n" If __name__== "__main__":  Treewalk (sys.argv[1])  printdict (DICT2)

How to use Remove c:/xx

Python implements the deletion of files of a specified size under a specified directory

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.