Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Print all directories, subdirectories and filenames

ShadowFlameShadowFlame Posts: 17Member
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:

cgi-bin
-source
--counter.php
-data
--main.php
images
-buttons
--small
---smalladv.gif
--adv.gif

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

Comments

  • SouldrinkerSouldrinker Posts: 143Member
    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: http://www.php.net/manual/de/class.dir.php

    best regards,

    sebastian mohrenstecher
    executive secretary
    net::allies

    www.net-allies.de
    info@net-allies.de

Sign In or Register to comment.