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 ...
随机推荐
- 洛谷 P1387 最大正方形 【dp】(经典)
题目链接:https://www.luogu.org/problemnew/show/P1387 题目描述 在一个n*m的只包含0和1的矩阵里找出一个不包含0的最大正方形,输出边长. 输入格式: 输入 ...
- python模块——PrettyTable
python模块——PrettyTable 一. 简介 Python通过prettytable模块将输出内容如表格方式整齐输出,可用来生成美观的ASCII格式的表格,十分实用. python本身并不内 ...
- 7,EasyNetQ-控制队列名称
EasyNetQ在为队列生成名称时的默认行为是使用 消息类型名称+subscription Id 例如,名称空间EasyNetQ.Tests.Integration中的PartyInvitatio ...
- 跳过从Win7/8升级,直接格式化全新安装 Windows 10 并自动永久激活系统的方法教程
跳过升级,直接激活全新 Win10 的方法步骤教程: 下载 Windows 10 系统的 ISO 镜像 在你当前的 Win7 / Win 8 / 8.1 系统中,使用 DaemonTools 或右键选 ...
- android db 导入 手机 系统 目录 data/data/包名/databases
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha ======== 需要权限, 权限不足. 就算root之后,把这些都改成了777权限,仍 ...
- psssss test
我觉得我不该写博客了
- HDU.5628.Clarke and math(狄利克雷卷积 快速幂)
\(Description\) \[g(i)=\sum_{i_1|i}\sum_{i_2|i_1}\sum_{i_3|i_2}\cdots\sum_{i_k|i_{k-1}}f(i_k)\ mod\ ...
- BZOJ 5381 or & Codeforces 623E Transforming Sequence DP+NTT
两道题题意都是一样的 不过$CF$的模数是$10^9+7$ 很简单的分析发现$A_i$项一定要有一个之前没有出现过的二进制位才能满足条件 考虑$DP$来做 设$f_{i,j}$表示$i$个数用了二进制 ...
- tomcat出现Error in dependencyCheck java.io.IOException: invalid manifest format
我只能说这个错误很坑爹,检查了很多地方都没问题,结果最后在MANIFEST.MF 里面把所有的空的行都删掉就好了.坑爹有木有.
- Window Server 2008 R2系统备份
1.安装Backup 2.打开Backup工具 3.一次性备份 下一步