python - Assembling output from a recursive function? -


i'm attempting loop through directory , nested directories within. seemed recursion way go it.

i ended code:

def get_file_list(directory=os.getcwd()):     in os.listdir(directory):         if os.path.isdir(i):             get_file_list(i)             continue         print 

this prints beautifully -- output expected. however, wanted take list of files , pass function further processing. tried compiling list.

def get_file_list(directory=os.getcwd()):     files = []     in os.listdir(directory):         if os.path.isdir(i):             get_file_list(i)             continue         files.append(i)     return files 

so now, problem returns files current working directory. after thinking, guess scoping issue. new files variable being created in unique piece of memory each time get_file_list() called, right? how around this? how assemble results nested calls?

all_files =[] current_dir,files,directories in os.walk("c:\\"):       current_files = [os.path.join(current_dir,file) file in files]       all_files.extend(current_files)   print files 

i think work better


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -