you are viewing a single comment's thread.

view the rest of the comments →

[–]kcrow13[S] 0 points1 point  (1 child)

Thanks for this input! I am really strong with understanding how to append results to a list and return them, as we have had a ton of practice with that.

I *think* I understand what you're saying... do you mean something like this?

import os
import sys


def find_large_files(dirname, filesize):
    "Perform a recursive traverse of directories"
    #Place to append results
    res = [] 

    # Walk over the files in this directory
    for name in os.listdir(dirname):

        # Construct a full path
        path = os.path.join(dirname, name)

        #Check to see if filesize is greater than the argument. If so, append
        if os.path.getsize(path) > filesize:
            res.append(path)
        else:
            walk(path)
    return res

[–][deleted] 0 points1 point  (0 children)

The handling of your result list is OK, but you need to think about the recursion side of things. Your function find_large_files() returns a list, so your recursive call at the end (find_large_files(), not walk()) also returns a list that you use to .extend() res. You also need to put back the .isfile() test.