清理用浏览器保存的网页资源,浏览器资源,一般我们用浏览器将网页保
清理用浏览器保存的网页资源,浏览器资源,一般我们用浏览器将网页保
一般我们用浏览器将网页保存下来时会产生两个文件:即 ".html"或".htm"和"*_files"文件夹。如果只要提取网页中的资源(比如图片),只需保留"???_files"文件夹,而"html"文件对于我们来说是没用的。
本程序的功能就是删除一个目录中所有的".html"或".htm"文件,并将"???_files"文件夹重命名为"???"。
# -*- coding: gb18030 -*-# by whypro# 2012-09-02import osdef clean_files(path): for file_name in os.listdir(path): full_name = os.path.join(path, file_name) # 如果是目录 if os.path.isdir(full_name): # 目录重命名 pos = file_name.find('_files') if pos > 0: new_name = file_name[:pos] os.rename(full_name, os.path.join(path, new_name)) print '%s --> %s' % (file_name, new_name) else: print '%s has skipped.' % file_name elif os.path.isfile(full_name): if (file_name.find('.html') > 0) or (file_name.find('htm')) > 0: os.remove(full_name) print '%s has removed.' % file_name else: print '%s has skipped.' % file_nameclean_files('C:\\\\文件夹')#该片段来自于http://byrx.net
相关内容
- 获取今天日期的指定格式,获取日期指定格式,可以制定
- Python通过ctypes调用windows api函数ShellExecute,ctypesshellex
- 输出乘法表到excel,输出乘法表excel,暂不支持xlsx格式
- 淘宝面试题猜数字游戏,淘宝试题猜数字,CNT 看到一个
- 太极,,matplotlib画散
- Python脚本写的命令行下的词典,python脚本,这个一个非常
- python 获得当前线程对象实例,python当前,python中的Thre
- 将经纬度转换为kml文件,经纬度转换kml文件,读取文件,
- Python下载百度空间文章,python百度文章,保存图片到本地
- python下载文件时显示下载进度的代码,,def report(c
评论关闭