下載了很多壓縮檔,就寫了一個指令碼
在Python中使用winrar命令,所以一般壓縮檔都支援
有些壓縮檔Python中還沒有相應的庫
你得先把winrar添加到path環境變數中
把代碼儲存為rar.py
在dos下使用,如:rar.py "D:/A B/C" mkdir
#rar.py<br />#decompress with winrar<br />#arguments :filename directory opt<br /># opt='mkdir' to create directory with the correspond filename<br /># opt='direct' to decompress rar files in current directory<br /># opt='mk&del' to mkdir and delete rar file<br />import os<br />import sys<br />if len(sys.argv)!=3:<br /> print ('wrong arguments/n')<br /> print ('rar.py directory opt/n')<br /> print ('opt=/'mkdir/' to create directory with the correspond filename/n')<br /> print ('opt=/'direct/' to decompress rar files in current directory/n')<br /> print ('opt=/'mk&del/' to mkdir and delete rar file/n')<br /> exit(0)</p><p>#-ibck ,minimized when running<br />opt=sys.argv[2]<br />os.chdir(sys.argv[1])<br />for file in os.listdir('.'):<br /> if os.path.isfile(file) and os.path.splitext(file)[1]=='.rar':<br /> if opt=='mkdir':<br /> cmd='winrar x -ibck "'+file+'"'+' "'+os.path.splitext(file)[0]+'"//'<br /> os.system(cmd)<br /> elif opt=='direct':<br /> cmd='winrar x -ibck "'+file+'"'<br /> os.system(cmd)<br /> elif opt=='mkdel':<br /> cmd='winrar x -ibck "'+file+'"'+' "'+os.path.splitext(file)[0]+'"//'<br /> os.system(cmd)<br /> os.remove(file)<br /> else :<br /> print('wrong option')</p><p>