To see this implemented without any modules, you can look at the following code (look at my note at the end, though):
#!perl use strict; use warnings; sub printDir { my $headDir = shift; # get starting directory our $indent = 3; # indentation our $increase = 3; # indentation steps sub recurseDir { my ($home, $dir) = @_; # get home directory and current di +rectory unless (-d "$home\\$dir") { # if it is a file print " " x $indent . "$dir\n"; # just print its name return; } print " " x $indent . "[$dir]\n"; # it's a dir, so print its nam +e fancily opendir(DIR, "$home\\$dir") # let's have a look at the dir +'s contents or die "Failed to open '$home\\$dir': $!\n"; my @filelist = readdir DIR; # get them closedir DIR; # close the handle $indent += $increase; # increase indentation for nex +t recursion level for (@filelist) { # iterate through dir contents next if ($_ eq '.' or $_ eq '..'); # ignore if . or .. recurseDir("$home\\$dir", $_); # and recurse otherwise } $indent -= $increase; # restore indentation } unless (-d "$headDir") { print " " x $indent . "$headDir\n"; return; } print " " x $indent . "[$headDir]\n"; opendir(DIR, $headDir) or die "Failed to open '$headDir': $!\n"; my @filelist = readdir DIR; closedir DIR; $indent += $increase; for (@filelist) { next if ($_ eq '.' or $_ eq '..'); recurseDir($headDir, $_); } } printDir 'C:\Dokumente';
In real life, however, (if it exists ;-) you should always use File::Find or a similar module to make your code more portable and easy to read. Furthermore ther are some traps, like links and such, which might render this simple solution useless. Conclusion: Always use File::Find or a similar module.
Hope this helped.
CombatSquirrel.
Entropy is the tendency of everything going to hell.

In reply to Re: script for directory mapping by CombatSquirrel
in thread script for directory mapping by chuleto1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.