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 tree.pl" or "perl win_tree.pl" 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 tree.pl.

I hope it will be useful.

Download tree.pl (For Linux)
Download win_tree.pl (For Windows Command Prompt)

4 comments:

  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.

    ReplyDelete
  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.

    ReplyDelete
  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:
    http://aplawrence.com/Bofcusm/1792.html

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


    +dir
    |-----filename

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

    ReplyDelete