logo CodeStepByStep logo

crawl

Language/Type: Python recursion file input

Write a recursive function named crawl that accepts a string for a file or directory name as a parameter and prints information about that file or directory. If the name represents a normal file, just prits name. If the name represents a directory, prits name and information about every file/directory inside it, indented by 4 spaces at each level. For example, the call of crawl("course") might print the following information about your course directory:

course
    handouts
        lecture-schedule.xls
        syllabus.doc
    homework
        1-gameoflife
            GameOfLife.zip
            life.h
            life.py

Show the files in a given directory sorted in alphabetical order.

Constraints: Your function must be recursive, though you may use a loop to help you as appropriate.

Function: Write a Python function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.