码迷,mamicode.com
首页 > 其他好文 > 详细

删除一定大小的文件

时间:2017-07-29 12:49:48      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:ant   文件夹   parent   路径   for   filename   move   file   port   

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)

删除一定大小的文件

标签:ant   文件夹   parent   路径   for   filename   move   file   port   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!