Print all directories, subdirectories and filenames

Is it possible to write a script that prints all directories, subdirectories and filenames of the directory it ist saved in one line of code an maybe less than 45 characters? But there should also be symbols that show, that this is a subdirectory. Example for output:


Some people said that it is possible to write it in one line? How?


  • Hey there,

    you need a recursive function to do so. There is an object called "dir" in php, which creates a virtual filehandle, letting you walk through the index of a directory.

    Now you have to write a function, reading out all files of the directory, and printing it out or saving it in an array, or something else. After printing a directory, you call the function itself, with the directory to read as parameter - and walk through this one, and so on and so on. Until the root-directory, which you defined in the first function call is readed out completely.

    Information on the dir-object of php you'll find here:

    best regards,

    sebastian mohrenstecher
    executive secretary

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion