0
所以最近我在這裏做了一個線程需要幫助的腳本,應該自動爲我提取.rar
文件和.zip
文件,沒有用戶交互。隨着人們的各種幫助我做出這樣的:(Python)問題與Linux命令unrar,不能爲我的生活找出爲什麼
import os
import re
from subprocess import check_call
from os.path import join
rx = '(.*zip$)|(.*rar$)|(.*r00$)'
path = "/mnt/externa/Torrents/completed/test"
for root, dirs, files in os.walk(path):
if not any(f.endswith(".mkv") for f in files):
found_r = False
for file in files:
pth = join(root, file)
try:
if file.endswith(".zip"):
print("Unzipping ",file, "...")
check_call(["unzip", pth, "-d", root])
found_zip = True
elif not found_r and file.endswith((".rar",".r00")):
check_call(["unrar","e","-o-", pth, root])
found_r = True
break
except ValueError:
print ("OOps! That did not work")
我第一次運行.rar文件這個腳本它工作驚人,它提取文件到正確的目錄和一切,但如果我再次運行它打印錯誤:
Extracting from /mnt/externa/Torrents/completed/test/A.Film/Subs/A.Film.subs.rar
No files to extract
Traceback (most recent call last):
File "unrarscript.py", line 20, in <module>
check_call(["unrar","e","-o-", pth, root])
File "/usr/lib/python2.7/subprocess.py", line 541, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['unrar', 'e', '-o-', '/mnt/externa/Torrents/completed/test/A.Film/Subs/A.Film.subs.rar', '/mnt/externa/Torrents/completed/test/A.Film/Subs']' returned non-zero exit status 10
所以我試圖用一個try /除外,但我不認爲我這樣做是正確的,任何人都可以對這個劇本收尾幫助嗎?
是那裏的文件? 「沒有文件提取」似乎unrar無法找到它 – marcadian
是的,該文件在那裏。 – nillenilsson