脚本清清心书卷哪里买买

一个简洁的Python清理脚本 - 开源中国社区
当前访客身份:游客 [
当前位置:
发布于 日 17时,
适用于各个平台,可以清理过期的文件和文件夹,非常方便。
代码片段(1)
1.&[代码][Python]代码&&&&
#coding:utf-8
Created on Aug 31, 2015
@author: mac
import os,time,sys
def remove(path):
Remove the file or directory
if os.path.isdir(path):
os.rmdir(path)
except OSError,e:
print "Unable to remove folder: %s"%path
print "The Detail error is: %s"%e.getMessage()
if os.path.exists(path):
os.remove(path)
except OSError,e:
print "Unable to remove file: %s"%path
print "The Detail error is: %s"%e.getMessage()
def cleanup(number_of_days,path):
Removes files from the passed in path that are older than or equal
to the number_of_days
time_in_sec=time.time()-(number_of_days*24*60*60)
for root,dirs,files in os.walk(path,topdown=False):
for file_ in files:
full_path=os.path.join(root,file_)
stat=os.stat(full_path)
if stat.st_mtime&=time_in_sec:
remove(full_path)
if not os.listdir(root):
remove(root)
if __name__ == '__main__':
days, path = int(sys.argv[1]), sys.argv[2]
cleanup(days, path)
开源中国-程序员在线工具:
相关的代码(100)
os.rmdir 只能清除空目录,假如目录下有文件时要raise OSError,在删除目录的时候建议做递归的删除
开源从代码分享开始
雪域兔子的其它代码[技巧] windows系统垃圾清理脚本_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
评价文档:
[技巧] windows系统垃圾清理脚本
上传于||暂无简介
大小:2.82KB
登录百度文库,专享文档复制特权,财富值每天免费拿!
你可能喜欢}

我要回帖

更多关于 暴风城清心书卷哪里买 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信