Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Almanac: Recursive File Listing

The printFileTree() function below will print an entire file tree to Stdout.

import tango.io.FilePath;
import tango.io.Stdout;

void printFileTree(FilePath root){
    void loadDelegate(char[] prefix, char[] str, bool isDirectory){
        // skip the "current dir" and "parent dir" entries
        if(str == "." || str == "..") return 1;
            
        auto path = prefix~str;
        if(isDirectory){
            // recurse
            (new FilePath(path)).toList(&loadDelegate);
        }
        else{
            // output the path to the console
            Stdout(path).newline;
        }               
        return 1;
    }
    root.toList(&loadDelegate);
}