logo CodeStepByStep logo

crawl

Language/Type: C++ recursion file input
Related Links:
Author: Marty Stepp (on 2016/07/06)

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 print its name. If the name represents a directory, print its 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.cpp
            life.h

You may want to use the methods of filelib.h (linked on this page) to help you.

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

Type your C++ solution code here:


This is a function problem. Write a C++ function as described. Do not write a complete program; just the function(s) above.

You must log in before you can solve this problem.


Log In

Need help?

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.

© Marty Stepp, all rights reserved.