日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python解压打开文件过多_自动解压大量压缩文件 Python 脚本 | 学步园

發(fā)布時間:2024/4/13 python 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python解压打开文件过多_自动解压大量压缩文件 Python 脚本 | 学步园 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

之前寫了一個自動解壓壓縮文件到壓縮文件所在文件夾的腳本

后根據(jù)自己需要,寫了另外兩個。原理一樣

都是使用winrar的命令

第一個腳本沒考慮周到,只能解壓rar文件

改進后可以支持winrar支持的各種文件

把指定文件夾下的文件保存到指定文件夾

#rardir.py

import os

import sys

src=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)

第一個版本的改進

#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 file

import os

import sys

if 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 running

opt=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)

elif opt=='diredel':

cmd='winrar x -ibck "'+file+'"'

os.system(cmd)

os.remove(file)

elif opt=='mkdel':

cmd='winrar x -ibck "'+file+'"'+' "'+os.path.splitext(file)[0]+'"//'

os.system(cmd)

os.remove(file)

else :

print('wrong option')

總結(jié)

以上是生活随笔為你收集整理的python解压打开文件过多_自动解压大量压缩文件 Python 脚本 | 学步园的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。