所以最近我在这里做了一个关于需要脚本帮助的线程,该脚本应该自动为我提取.rar
文件和.zip
文件,无需用户交互。在人们的各种帮助下,我做到了:
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/except 但我认为我做的不对,有人可以帮助完成这个脚本的最后润色吗?