ru=lambda x:x.decode('u8')
rp=lambda x:x.replace('\\','/')
gb=lambda x:x.decode('gbk')
class ZIP:
def __init__(s):
import zipfile,ntpath,listdir,appuifw
s.ZF,s.NP,s.LD,s.A=zipfile.ZipFile,ntpath,listdir,appuifw
del zipfile,ntpath,listdir,appuifw
s.list,s.zip=[ru('请选择文件')],None
s.oldbody=s.A.app.body
s.A.app.body=s.LIST=s.A.Listbox(s.list)
s.menu()
s.L=s.A.e32.Ao_lock()
s.A.app.exit_key_handler=s.L.signal
s.L.wait()
def run(s,arg,dir,files):
for i in files:
if s.NP.isdir(dir):
if dir[-1]!=dir[2]:dir+=dir[2]
if s.NP.isfile(dir+i):s.list.append(rp(dir+i))
def zip_co(s):
s.path=s.LD.fm(find='dir')
s.NP.walk(path,run,'\n')
ZIP=s.ZF(path+'1.zip','w',8)
for i in s.list:
i=i[len(path):]
ph=path1.split('/')[-2]+'/'
print ru('正在处理:'+ph+i)
try:ZIP.write(path+i,ph+i)
except:print 'error';break
ZIP.close()
print ru('操作完成!')
def dezip(s,ph,run):
w=s.ZF(ph,'r')
nl=w.namelist()
for i in nl:run(w,i)
w.close();return nl
def zip_de(s):
def run(w,i):
s.path='e:/cai/'+i
r=w.read(i)
print ru('正在处理:'+i)
ph=s.NP.split(path)[0]
if not s.NP.exists(ph):os.makedirs(ph)
open(path,'w').write(r)
s.path=s.LD.fm(find='file',ext=['.zip'])
s.dezip(s.path,run)
print ru('操作完成!')
def zip_del(s):
def run(w,i):
index=s.LIST.current()
r=w.read(i)
try:ii=ru(i)
except:ii=gb(i)
if ii!=s.nl2[index]:zipf.writestr(w.getinfo(i), r)
zipf=s.ZF(s.path+'_1.zip','w')
s.dezip(s.path,run)
def zip_open(s):
s.path=s.LD.fm(find='file',ext=['.zip'])
s.zip=s.ZF(s.path)
try:s.nl2=[ru(i) for i in s.zip.namelist()]
except:s.nl2=[gb(i) for i in s.zip.namelist()]
s.LIST.set_list(s.nl2)
s.menu()
def menu(s):
if s.zip:s.A.app.menu=[(ru('解压'),s.zip_de),(ru('提取'),s.zip_de),(ru('删除'),s.zip_del),(ru('返回'),s.__init__)]
else:s.A.app.menu=[(ru('打开'),s.zip_open),(ru('压缩'),s.zip_co)]
zip=ZIP()

  

Python压缩的更多相关文章

  1. Python压缩指定文件及文件夹为zip

    Python压缩指定的文件及文件夹为.zip 代码: def zipDir(dirpath,outFullName): """ 压缩指定文件夹 :param dirpat ...

  2. 【Python】使用Python压缩文件/文件夹

    [Python压缩文件夹]导入“zipfile”模块 def zip_ya(startdir,file_news): startdir = ".\\123" #要压缩的文件夹路径 ...

  3. Python压缩文件/文件夹

    [Python压缩文件夹]导入“zipfile”模块 def zip_ya(startdir,file_news): startdir = ".\\123" #要压缩的文件夹路径 ...

  4. python压缩pdf(指定缩放比例)

    python压缩pdf(指定缩放比例) 原理 pdf文件处理使用https://pymupdf.readthedocs.io/en/latest/index.html库可以轻松实现,该库的官方说明文档 ...

  5. python 压缩 解压缩 文件

    1. 用zipfile模块打包文件或是目录.解压zip文件 http://wangwei007.blog.51cto.com/68019/1045577 #!/usr/bin/env python # ...

  6. python压缩文件

    #coding=utf-8 #压缩文件 import os,os.path import zipfile #压缩:传路径,文件名 def zip_compression(dirname,zipfile ...

  7. python 压缩文件为zip后删除原文件

    压缩.log 文件为zip后删除原文件 需要注意:本人作为小白,该脚本需要和.log在一起,后面有时间需要改正. #!/usr/local/python/bin/python #-*-coding=u ...

  8. python 压缩模块大杂烩(zipfile,bz2,lzma,gzip,tarfile,zlib)

    [*] 以下压缩模块请结合python的官方文档(https://docs.python.org/3.5/library/index.html)来实践或者对比(我的是python 3.5) 1.pyt ...

  9. Python压缩&解压缩

    Python中常用的压缩模块有zipfile.tarfile.gzip 1.zipfile模块的简单使用 import zipfile # 压缩 z1 = zipfile.ZipFile('zip_t ...

随机推荐

  1. struts2漏洞与修复

    步骤: 1.下载struts-2.3.16.3-all, D:\TEST\struts2.3.16.3 2.替换jar,参考 http://blog.csdn.net/spyjava/article/ ...

  2. CURL命令详解

    curl命令是一个强大的网络工具,它能通过http,ftp等方式下载.上传文件.其中curl远不止这些功能,大家可以通过阅读手册获取更多的信息,类似的工具还有wget. curl命令使用了libcur ...

  3. sqlite嵌入式数据库C语言基本操作(2)

    :first-child{margin-top:0!important}img.plugin{box-shadow:0 1px 3px rgba(0,0,0,.1);border-radius:3px ...

  4. 笔记汇总.md

    ```javascript 1.js对象,value的值取不到,试着将引入的js文件放到body的后面 $("input[type='time']").change( functi ...

  5. asp.net timer viewstate

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  6. Metro-Ural119递推

    Time limit: 0.5 second Memory limit: 64 MB Many of SKB Kontur programmers like to get to work by Met ...

  7. LAMP环境搭建 (原创帖,转载请注明出处)

    =============================说在前面的话==========================第一安装Mysql第二安装Apache-httpd第三安装PHP 第四配置PH ...

  8. SQL锁死解决办法

    SQL Server 表,记录 死锁解决办法 1. 先根据以下语句 查询 哪些表被 死锁,及 死锁的 spid SELECT request_session_id spid,OBJECT_NAME(r ...

  9. R:incomplete final line found by readTableHeader on

      报错: In read.table("abc.txt", header = T) :  incomplete final line found by readTableHead ...

  10. 理解 JavaScript 作用域和作用域链

    http://www.cnblogs.com/lhb25/archive/2011/09/06/javascript-scope-chain.html