python学习笔记(23)——python压缩bin包
说明(2017-12-25 10:43:20):
1. CZ写的压缩bin包代码,记下来以后好抄。
# coding:utf-8
'''
Created on 2014年8月14日 @author: johnsoncheng
''' import zipfile, os IGNORE_POSTFIX_LIST = {".mp3", ".wav", ".jpg", ".JPG", ".wma", ".png", ".mp4", ".avi", ".wmv"} def zipFolder():
# srcFolder = r"E:\XZJYRootFolder\root\Math_Video"
# tarFile = r"E:\XZJYRootFolder\root\Data\Math_Video.zip"
rootFolder = r"D:\软件发布\压缩根目录"
#rootFolder = r"D:\XZJYRootFolder\root\Data1\res"
# 遍历所有文件夹
folderList = os.listdir(rootFolder)
for folder in folderList:
folderPath = os.path.join(rootFolder, folder)
if os.path.isdir(folderPath):
# 取得二级目录
folderList1 = os.listdir(folderPath)
for folder1 in folderList1:
folderPath1 = os.path.join(folderPath, folder1)
if os.path.isdir(folderPath1):
zipPath = os.path.join(folderPath, folder1 + ".bin")
with zipfile.ZipFile(zipPath, 'w', allowZip64=True) as myzip:
zipSubFolder(myzip, folderPath1, folderPath)
pass def zipSubFolder(zipObj, folderPath, rootFolderPath):
global IGNORE_POSTFIX_LIST
print("compressing " + folderPath)
# 取得当前文件夹差异路径
folderRelativePath = folderPath[len(rootFolderPath): ]
# 插入当前文件夹
zipObj.write(folderPath, folderRelativePath)
# 遍历所有子实体
entryList = os.listdir(folderPath)
# 处理所有子文件夹
for entry in entryList:
entryPath = os.path.join(folderPath, entry)
if os.path.isdir(entryPath):
zipSubFolder(zipObj, entryPath, rootFolderPath)
# 处理子文件
for entry in entryList:
entryPath = os.path.join(folderPath, entry)
if os.path.isfile(entryPath):
fileRelativePath = folderPath[len(rootFolderPath): ] + "/" + entry
tempRoot, tempPostFix = os.path.splitext(fileRelativePath)
if tempPostFix in IGNORE_POSTFIX_LIST:
zipObj.write(entryPath, fileRelativePath)
else:
zipObj.write(entryPath, fileRelativePath, zipfile.ZIP_DEFLATED)
pass if __name__ == '__main__':
print("************** start *************")
zipFolder()
print("************** end *************")
pass
python学习笔记(23)——python压缩bin包的更多相关文章
- python学习笔记13(模块、包)
在Python中有一个概念叫做模块(module),比如在Python中要调用sqrt函数,必须用import关键字引入math这个模块,下面就来了解一下Python中的模块. 模块文件以.py后缀结 ...
- python学习笔记(一):python简介和入门
最近重新开始学习python,之前也自学过一段时间python,对python还算有点了解,本次重新认识python,也算当写一个小小的教程.一.什么是python?python是一种面向对象.解释型 ...
- python 学习笔记 9 -- Python强大的自省简析
1. 什么是自省? 自省就是自我评价.自我反省.自我批评.自我调控和自我教育,是孔子提出的一种自我道德修养的方法.他说:“见贤思齐焉,见不贤而内自省也.”(<论语·里仁>)当然,我们今天不 ...
- python学习笔记之——python模块
1.python模块 Python 模块(Module),是一个 Python 文件,以 .py 结尾,包含了 Python 对象定义和Python语句. 模块让你能够有逻辑地组织你的 Python ...
- Python学习笔记 - day12 - Python操作NoSQL
NoSQL(非关系型数据库) NoSQL,指的是非关系型的数据库.NoSQL有时也称作Not Only SQL的缩写,是对不同于传统的关系型数据库的数据库管理系统的统称.用于超大规模数据的存储.(例如 ...
- python 学习笔记一——Python安装和IDLE使用
好吧,一直准备学点啥,前些日子也下好了一些python电子书,但之后又没影了.年龄大了,就是不爱学习了.那就现在开始吧. 安装python 3 Mac OS X会预装python 2,Linux的大多 ...
- python学习笔记(python简史)
一.python介绍 python的创始人为吉多·范罗苏姆(Guido van Rossum) 目前python主要应用领域: ·云计算 ·WEB开发 ·科学运算.人工智能 ·系统运维 ·金融:量化交 ...
- python学习笔记(1)--python特点
python诞生于复杂的信息系统时代,是计算机时代演进的一种选择. python的特点,通用语言,脚本语言,跨平台语言.这门语言可以用于普适的计算,不局限于某一类应用,通用性是它的最大特点.pytho ...
- python学习笔记23(时间与日期 (time, datetime包))
Python提供了多个内置模块用于操作日期时间,像calendar,time,datetime. time包 time包基于C语言的库函数(library functions).Python的解释器通 ...
- python学习笔记五:模块和包
一.模块用import导入 cal.py: #!/usr/bin/python def add(x,y): return x+y if __name__ == '__main__': print ad ...
随机推荐
- DB2<RedHed Linux> 创建数据库
1 DB2 安装后组情况 Users User Desc Username Home folder Password Group Administration User -dasusr1 /hom ...
- SQL Server中查找包含某个文本的存储过程
SELECT name,text from sysobjects o,syscomments s where o.id=s.id and text LIKE '%text%' and o.xtype= ...
- AFP溢出攻击模块afp/loginext
AFP溢出攻击模块afp/loginext 在苹果Mac OS X 10.3.3及以前版本,AFP服务存在缓存区溢出漏洞CVE-2004-0430.利用该漏洞,用户可以基于LoginExt包执行任 ...
- 模拟页面获取的php数据(四)
<?php $tqzf = [ "aData" => [//通勤方式 "trafficType" => [ 0 => [ "t ...
- Node+Express+MongoDB + Socket.io搭建实时聊天应用实战教程(三)--前后端环境配置
前言 之前都是介绍一些基础知识,在这一节,我们就要开始实战coding了.正所谓磨刀不误砍柴工,准备工作显得尤为重要.很多demo只是追求效果的实现,并不注重整个demo的架构性.从我个人的角度看来, ...
- 安卓工作室 android studio 谷歌账号 登录
作者:韩梦飞沙 Author:han_meng_fei_sha 邮箱:313134555@qq.com E-mail: 313134555 @qq.com 登录你的谷歌账号,开始 添加 云功能 到你的 ...
- 潭州课堂25班:Ph201805201 python 操作数据库 第五课 (课堂笔记)
一 用 python 操作 mysql 1,导入 pymysql 2,检查配置文件, 3,端口转发 如果 python 在本机,数据库在远程,或虚拟机则需要 4用 python 连接 # -*- co ...
- Bracket 使用指南
Brackets 是一个免费.开源且跨平台的 HTML/CSS/JavaScript 前端 WEB 集成开发环境 (IDE工具).该项目由Adobe 创建和维护,根据MIT许可证发布,支持 Windo ...
- mxnet安装及NDArray初体验
一.mxnet安装 (以下均为mac环境) 有二种方式: 1.1 用conda安装 #创建gluon目录 mkdir gluon-tutorials && cd gluon-tutor ...
- Redis 常用监控信息命令总结
查看启动到当前处理命令总数: # redis-cli info stats | grep total_commands total_commands_processed:23693286991 查看每 ...