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 ...
随机推荐
- iOS 技术篇: 如何利用dsym文件分析苹果被拒日志
今天提审被拒了.伤心
- Session失效后所有Ajax请求跳转登录地址
当登录的Session失效后,采用ajax请求数据时会没有反应,这时候应该自动跳转到登录页面,让用户重新登录. 全局配置以下可实现 $(function() { $.ajaxSetup({ compl ...
- luogu P2934 [USACO09JAN]安全出行Safe Travel
题目链接 luogu P2934 [USACO09JAN]安全出行Safe Travel 题解 对于不在最短路树上的边(x, y) 1 | | t / \ / \ x-----y 考虑这样一种形态的图 ...
- 洛谷.T22136.最长不下降子序列(01归并排序 分治)
题目链接 \(Description\) 给定一个长为n的序列,每次可以反转 \([l,r]\) 区间,代价为 \(r-l+1\).要求在\(4*10^6\)代价内使其LIS长度最长,并输出需要操作的 ...
- ModelForm的使用
from django.forms import Form,ModelForm,fields,widgets as wd class QueModelForm(ModelForm): class Me ...
- React系列文章:Babel编译JSX生成代码
上次我们总结了React代码构建后的Webpack模块组织关系,今天来介绍一下Babel编译JSX生成目标代码的一些规则,并且模拟整个生成的过程. 我们还是拿最简单的代码举例: import {gre ...
- c# 上传图片流,php端(laravel框架)接收处理方法
c# httppost方法 public struct PostFile { public string name; public string filename; public Stream bit ...
- java程序中实现打开 某个指定浏览器
package com.test; import java.lang.reflect.Method; //实现打开浏览器并跳到指定网址的类 public class BareBonesBrowserL ...
- 关于在win8系统下用VMware 9.0装系统导致物理机不断重启的解决办法
一.问题描述 前段时间将操作系统换成了Win8,安装上VMware 9.0英文版.然后在VMware中安装centos系统,结果每次到安装系统的时候,物理机系统就会莫名其妙地自动重启,毫无征兆地出现, ...
- error LNK1104:无法打开文件"lua51.lib"
今天学习C++与Lua通信,遇到了问题:fatal error LNK1104: 无法打开文件“lua51.lib” 开发环境: VS2012 cocos版本:cocos2d-x-3.0 已经按书&l ...