擅长:python、mysql、java
<p>下面的例子将直接起作用!按照@Padraic的建议,我替换了操作系统使用更合适的子流程。在</p>
<p>将所有文件合并到一个字符串中并在字符串中查找*.mkv怎么样?在</p>
<pre><code>import os
import re
from subprocess import check_call
from os.path import join
rx = '(.*zip$)|(.*rar$)|(.*r00$)'
path = "/mnt/externa/folder"
regex_mkv = re.compile('.*\.mkv\,')
for root, dirs, files in os.walk(path):
string_files = ','.join(files)+', '
if regex_mkv.match(string_files): continue
for file in files:
res = re.match(rx, file)
if res:
# use os.path.join
pth = join(root, file)
# it can only be res.group(1) or one of the other two so we only need if/else.
if res.group(1):
print("Unzipping ",file, "...")
check_call(["unzip" , pth, "-d", root])
else:
check_call(["unrar","e", pth, root])
</code></pre>