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";
}