I'm writing this python script to recursively go through a directory and use the unrar utility on ubuntu to open all .rar files. For some reason it will enter the directory, list some contents, enter the first sub-directory, open one .rar file, then print all the other contents of the parent directory without going into them. Any ideas on why it would be doing this? I'm pretty new to python, so go easy.
"""Recursively unrars a directory"""
import subprocess
import os
def runrar(directory):
os.chdir(directory)
dlist = subprocess.check_output(["ls"])
for line in dlist.splitlines():
print(line)
if isRar(line):
print("unrar e " + directory + '/' + line)
arg = directory + '/' + line
subprocess.call(['unrar', 'e', arg])
if os.path.isdir(line):
print 'here'
runrar(directory + '/' + line)
def isRar(line):
var = line[-4:]
if os.path.isdir(line):
return False
if(var == ".rar"):
return True
return False
directory = raw_input("Please enter the full directory: ")
print(directory)
runrar(directory)