说明(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包的更多相关文章

  1. python学习笔记13(模块、包)

    在Python中有一个概念叫做模块(module),比如在Python中要调用sqrt函数,必须用import关键字引入math这个模块,下面就来了解一下Python中的模块. 模块文件以.py后缀结 ...

  2. python学习笔记(一):python简介和入门

    最近重新开始学习python,之前也自学过一段时间python,对python还算有点了解,本次重新认识python,也算当写一个小小的教程.一.什么是python?python是一种面向对象.解释型 ...

  3. python 学习笔记 9 -- Python强大的自省简析

    1. 什么是自省? 自省就是自我评价.自我反省.自我批评.自我调控和自我教育,是孔子提出的一种自我道德修养的方法.他说:“见贤思齐焉,见不贤而内自省也.”(<论语·里仁>)当然,我们今天不 ...

  4. python学习笔记之——python模块

    1.python模块 Python 模块(Module),是一个 Python 文件,以 .py 结尾,包含了 Python 对象定义和Python语句. 模块让你能够有逻辑地组织你的 Python ...

  5. Python学习笔记 - day12 - Python操作NoSQL

    NoSQL(非关系型数据库) NoSQL,指的是非关系型的数据库.NoSQL有时也称作Not Only SQL的缩写,是对不同于传统的关系型数据库的数据库管理系统的统称.用于超大规模数据的存储.(例如 ...

  6. python 学习笔记一——Python安装和IDLE使用

    好吧,一直准备学点啥,前些日子也下好了一些python电子书,但之后又没影了.年龄大了,就是不爱学习了.那就现在开始吧. 安装python 3 Mac OS X会预装python 2,Linux的大多 ...

  7. python学习笔记(python简史)

    一.python介绍 python的创始人为吉多·范罗苏姆(Guido van Rossum) 目前python主要应用领域: ·云计算 ·WEB开发 ·科学运算.人工智能 ·系统运维 ·金融:量化交 ...

  8. python学习笔记(1)--python特点

    python诞生于复杂的信息系统时代,是计算机时代演进的一种选择. python的特点,通用语言,脚本语言,跨平台语言.这门语言可以用于普适的计算,不局限于某一类应用,通用性是它的最大特点.pytho ...

  9. python学习笔记23(时间与日期 (time, datetime包))

    Python提供了多个内置模块用于操作日期时间,像calendar,time,datetime. time包 time包基于C语言的库函数(library functions).Python的解释器通 ...

  10. python学习笔记五:模块和包

    一.模块用import导入 cal.py: #!/usr/bin/python def add(x,y): return x+y if __name__ == '__main__': print ad ...

随机推荐

  1. hdu 1106 去5排序

    题目链接:https://vjudge.net/problem/HDU-1106 题目大意: 输入一行数字,如果我们把这行数字中的‘5’都看成空格,那么就得到一行用空格分割的若干非负整数(可能有些整数 ...

  2. IT 产品 需求 痛点

    英文应该有个 汉语发音 标注 这样的平台软件.罗马音.

  3. u3d 地形 U3d terrain

    u3d 地形 U3d terrain 作者:韩梦飞沙 Author:han_meng_fei_sha 邮箱:313134555@qq.com E-mail: 313134555 @qq.com fbx ...

  4. prufer序列计数的一些结论

    \(prufer\)序列和完全图的生成树一一对应(考虑构造) 完全图的生成树个数为\(n^{n - 2}\) 满足第\(i\)个点的度数为\(d_i\)的生成树为\(\frac{n!}{\prod ( ...

  5. Codeforces.1051F.The Shortest Statement(最短路Dijkstra)

    题目链接 先随便建一棵树. 如果两个点(u,v)不经过非树边,它们的dis可以直接算. 如果两个点经过非树边呢?即它们一定要经过该边的两个端点,可以直接用这两个点到 u,v 的最短路更新答案. 所以枚 ...

  6. [CF1030E]Vasya and Good Sequences

    [CF1030E]Vasya and Good Sequences 题目大意: 给定一个长度为\(n(n\le3\times10^5)\)的数列\(a_i(1\le a_i\le10^{18})\). ...

  7. Git问题Everything up-to-date解决

    Git问题Everything up-to-date解决 [自己的亲身错误体验] 我的上一篇博客,说了怎么上传一个项目到git远程上面.今天我写好一个小栗子,准备再次上传的时候.我依旧是放在我的F:\ ...

  8. 在web中实现当前变量和前一个的比较

    /*if (attribute == null) {// 如果缓存中没有存过UploadTimeObj对象,那么创建对象,并将该对象存入缓存中                    UploadTim ...

  9. spyder 安装

    https://www.cnblogs.com/pcat/p/5398997.html

  10. Android:Unable to find explicit activity class

    写了两个Activity,确定java代码和xml配置文件没问题之后,运行工程,报错: E/AndroidRuntime(10513): FATAL EXCEPTION: main E/Android ...