I'm fairly new to all this so if anyone has pointers for my script please speakup.

My solution was to use the glob() function and loop through the results looking for the next set if directories. I guess you could count the number of times the loop is run to limit the depth or you could have a target directory to stop and break out of the loop.

The purpose of this script is to make links to all the files it finds. It is a helpful script to convert files from one system to another where users have comeup with crazy files names. Hope this helps.

#!/usr/bin/perl -w #Do Not run as Root, this may cause dirs to be link and corrupt the; #file system; my $start; my @in; my @big; my @next; my $level; my $dir; my @files; my $file; my $z=0; my $target; print "\n\n ***********************************\n"; print "This script will create (symbolic) links recursively\n"; print "to all files in the specifiled directory and also create\n"; print "the links from the directory specified\n"; print " ***********************************\n\n"; print " Please enter the starting target directory\n"; print " (don't end with a slash)\n"; $start=<STDIN>; chomp $start; print " \nEnter the working dir where you would like\n"; print " the links to be placed?\n"; print " (don't end with a slash)\n"; $target=<STDIN>; chomp $target; @in = (glob("$start*/")); @big = (@in); do { @next = (@in); @in = (); foreach $level (@next) { @in = (@in, (glob("$level*/")))} @big = (@big, @in); @next = ();} while $in[0]; foreach $dir (@big) { @files = (@files, (glob("$dir*"))); } foreach $file (@files) { $z=$z+1; $link = "$target"."/"."$z"; print "$z \-\- $file\n"; # to creat a symbolic link change link to symlink; link("$file","$link") || warn "can't link to file $file\n"; }

In reply to Re: How do I recursively create a directory tree/filesystem? by Anonymous Monk
in thread How do I recursively create a directory tree/filesystem? by fensterblick

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.