I am writing a piece of code to recursively processing *.py files. The code block is as the following:
class FileProcessor(object):
def convert(self,file_path):
if os.path.isdir(file_path):
""" If the path is a directory,then process it recursively
untill a file is met"""
dir_list=os.listdir(file_path)
print("Now Processing Directory:",file_path)
i=1
for temp_dir in dir_list:
print(i,":",temp_dir)
i=i+1
self.convert(temp_dir)
else:
""" if the path is not a directory"""
""" TODO something meaningful """
if __name__ == '__main__':
tempObj=FileProcessor()
tempObj.convert(sys.argv[1])
When I run the script with a directory path as argument, it only runs the first layer of the directory, the line:
self.convert(temp_dir)
seems never get called. I'm using Python 3.5.
os.walk