python删除N天前文件
2015-06-30 23:45
525 查看
#/usr/bin/env python # -*- coding:utf-8 -*- #Author='Jun' import os import sys import time def removefiles(beftime, defalutpath='.'): for i in os.listdir(path): filename = path + os.sep + i if os.path.getmtime(filename) < beftime: try: if os.path.isfile(filename): os.remove(filename) elif os.path.isdir(filename): os.removedirs(filename) else: os.remove(filename) print "%s remove success." % filename except Exception as error: print error print "%s remove faild." % filename if __name__ == "__main__": try: path = sys.argv[1] breday = int(sys.argv[2]) bretime = time.time() - 3600 * 24 * breday removefiles(bretime, path) except Exception as e: print e sys.exit(-1)
本文出自 “拥抱开源” 博客,请务必保留此出处http://junit.blog.51cto.com/9897514/1669578
相关文章推荐
- python numpy矩阵和数组的转换
- Think In Python Exercise
- python 简单图像处理(13)
- Python学习之二【初学Python】
- 最近在学习python
- python装饰器
- python 优秀文章索引
- python编程之键盘响应
- Python学习十四:filter()
- Python图像处理(12):贝叶斯分类器
- python脚本
- Python实现决策树算法
- Python学习十三:map/reduce
- Python Decorator
- windows系统下Python环境的搭建
- Python LoggerAdpater类
- python ConfigParse模块(转)
- Python-strip()方法
- python中的元类metaclass
- Python文件操作