本帖最后由 唐伯虎(0) 于 2019-1-24 13:45 编辑
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)
|
|