import osimport os.pathfilePath = input(‘Enter filepath : ‘)size=int(input(‘Enter the max size you want to delete(KB):‘))#三个参数:分别返回1.父目录 2.所有文件夹名字(不含路径) 3.所有文件名字for parent ,dirnames , filenames in os.walk(filePath):# for dirname in dirnames: #这些用不到# print( ‘parent is :‘+parent) #这些用不到# print (‘dirname is ‘+ dirname #这些用不到 for filename in filenames: print(‘parent is :‘ + parent) print(‘filename is :‘ + filename) currentPath = os.path.join(parent, filename) print(‘the fulll name of the file is :‘ + currentPath) filesize = os.path.getsize(currentPath) / 1024 print(‘the file size is : %.3f KB‘ % (filesize)) if filesize<size: os.remove(currentPath)
时间: 2024-10-07 21:14:09