For this problem, the goal is to write code for finding all files under a directory (and all directories beneath it) that end with ".c"
Here is an example of a test directory listing, which can be downloaded here:
./testdir ./testdir/subdir1 ./testdir/subdir1/a.c ./testdir/subdir1/a.h ./testdir/subdir2 ./testdir/subdir2/.gitkeep ./testdir/subdir3 ./testdir/subdir3/subsubdir1 ./testdir/subdir3/subsubdir1/b.c ./testdir/subdir3/subsubdir1/b.h ./testdir/subdir4 ./testdir/subdir4/.gitkeep ./testdir/subdir5 ./testdir/subdir5/a.c ./testdir/subdir5/a.h ./testdir/t1.c ./testdir/t1.h Python's os module will be useful—in particular, you may want to use the following resources:
os.path.isdir(path)
os.path.isfile(path)
os.listdir(directory)
os.path.join(...)
Note: os.walk() is a handy Python method which can achieve this task very easily. However, for this problem you are not allowed to use os.walk().
Here is some code for the function to get you started:
def find_files(suffix, path): """ Find all files beneath path with file name suffix.
Note that a path may contain further subdirectories
and those subdirectories may also contain further subdirectories.
There are no limit to the depth of the subdirectories can be.
Args:
suffix(str): suffix if the file name to be found
path(str): path of the file system
Returns:
a list of paths
"""
return None
Note: While testing the program you should unzip the testdir.zip on the same directory. Or you can use any of uncompressed folder on the same directory that you want to search.