Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: How do I recursively create a directory tree/filesystem?

by Anonymous Monk
on Aug 14, 2002 at 11:35 UTC ( [id://190034]=note: print w/replies, xml ) Need Help??


in reply to How do I recursively create a directory tree/filesystem?

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://190034]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-04-24 02:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found