Friday, April 18, 2008

Perl Script for Directory Tree

I have created perl script to have tree view of the directory. It is developed for the shell (linux shell and windows command prompt) which doesn't support 'tree' command. If your shell already have tree command, then this script is of not much importance. But you can do some customization in tree view using this script.

This script scans directory recursively and then displays the tree view. Using "-width" argument tree view can be compressed or expanded. To display how to give arguments to script type "perl" or "perl" on the shell. Follow the instructions displayed in the help. One need to have perl package installed in the system for this script to work. Default $expand_size = 5 and $max_width = 10. expand_size decides how much is the space in between "+" and "name of directory or file". $max_width is the maximum value of expand_size. User can increase default $expand_size and $max_width by editing

I hope it will be useful.

Download (For Linux)
Download (For Windows Command Prompt)


  1. yes very useful. thank you.

    can you advise a way to highlight directories from files.

    for example.. when i paste onto excel.. i want to highlight the directories in RED by doing a filter of all the directories.

  2. Very useful script.. thanks.

    Some problems with it:
    - has problems when directory or file name have spaces
    - has problems when some directory has the . or (wild characters)

    I am also trying to customize it to include file size and modified date... with some success but not that great.. as I have to really understand your code in detail.

    Could you assist on those areas and the above comments.

  3. Forgot one more thing..

    may be using File::Find may be more easier to customize.. i think.

    using the part of the code from here:

    the tidying up is excellent in your code.. but i am trying to decipher how to modify it to my needs.


  4. Works great on MacOS, thanks! Would be nice with a -d option for directories only.