磁盘垃圾文件

from os import remove, listdir, chmod, statfrom os.path import isdir, join, splitext
import sys

#要删除的文件类型type= ['.tmp', '.log', '.obj', '.txt']
filetypes 
def delFiles(directory):
       for filename in listdir(directory):
       temp = join(directory, filename)
       if isdir(temp):
            delFiles(temp)
       elif splitext(temp)[1] in type or stat(temp).st_size==0:
              #修改权限
               chmod(temp, 0o777)
                #删除
                remove(temp)
                print(temp)

if __name__ == '__main__':
paths = sys.argv[1:]
for path in paths:
     if isdir(path):
          deFiles(path)

更多技术资讯可关注:gzitcast

猜你喜欢

转载自www.cnblogs.com/heimaguangzhou/p/11585526.html