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