首页 > 其他 > 详细

删除一定大小的文件

时间:2017-07-29 12:30:45      阅读:194      评论:0      收藏:0      [点我收藏+]
import os
import os.path
filePath = 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)

删除一定大小的文件

原文:http://www.cnblogs.com/gilgamesh-hjb/p/7255437.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!