用Python解压缩rar、zip文件的方法,python解压缩rarzip,编橙之家本文为大家提供关
用Python解压缩rar、zip文件的方法,python解压缩rarzip,编橙之家本文为大家提供关
编橙之家本文为大家提供关于用Python解压缩rar、zip文件的方法源码。Python语言对文件方面的处理还是很方便的,例如以前有为大家介绍过Python读取分割压缩TXT文本文件的方法、Python批量删除windows下svn文件夹的方法等,都是很实用的文件相关操作方法。python脚本如何解压指定路径下的所有rar文件?
下边就来看下用Python解压缩rar、zip文件的方法源码:
import osimport syssrc=sys.argv[1]dst=sys.argv[2]format=['rar','zip','7z','ace','arj','bz2','cab','gz','iso','jar','lzh','tar','uue','z']os.chdir(sys.argv[1])for file in os.listdir('.'):if os.path.isfile(file) and (os.path.splitext(file)[1][1:].lower() in format)==True:#cmd='winrar x -ibck "'+file+'" "'+dst+'\\'+os.path.splitext(file)[0]+'\\"'cmd='winrar x -ibck "'+file+'" "'+dst+'\\"'os.system(cmd)os.remove(file)print('done '+file) #www.iplaypy.com第一个版本的改进#rardecmp.py#decompress with winrar#arguments :filename directory opt# opt='mkdir' to create directory with the correspond filename# opt='direct' to decompress rar files in current directory# opt='mk&del' to mkdir and delete rar fileimport osimport sysif len(sys.argv)!=3:print ('wrong arguments\n')print ('rar.py directory opt\n')print ('opt=\'mkdir\' to create directory with the correspond filename\n')print ('opt=\'direct\' to decompress rar files in current directory\n')print ('opt=\'diredel\' to decompress rar files in current directory and delete files\n')print ('opt=\'mkdel\' to mkdir and delete rar file\n')exit(0)#-ibck ,minimized when runningopt=sys.argv[2]os.chdir(sys.argv[1])format=['rar','zip','7z','ace','arj','bz2','cab','gz','iso','jar','lzh','tar','uue','z']for file in os.listdir('.'):if os.path.isfile(file) and (os.path.splitext(file)[1][1:].lower() in format)==True:if opt=='mkdir':cmd='winrar x -ibck "'+file+'"'+' "'+os.path.splitext(file)[0]+'"\\'os.system(cmd)elif opt=='direct':cmd='winrar x -ibck "'+file+'"'os.system(cmd)
编橙之家Python文件解压相关文章推荐:Python Gzip压缩与解压模块、python 打开文件
编橙之家文章,
相关内容
- 游戏水桶倒水问题Python语言的解决方法,倒水python,Py
- Python算法--最长公共子串算法代码讲解,python算法,Pyt
- 如何用Python os.path.walk方法遍历搜索文件内容的操作详解
- Python脚本随机生成中文验证码源码实例分析,python实例
- Python标准库模块之Sys使用详解,python使用详解,本文主要
- 本地服务更新Python代码 如要使用请适当的修改,pytho
- python抽奖 系统算法代码的简单实现,python抽奖算法代码
- 如何用Python代码实现自动比较两个文件中的代码变化?
- python logging 日志模块使用方法学习,pythonlogging,本文为
- Python近期使用较少算法实现方法,python近期较少算法
评论关闭