Friday, November 24, 2006

[perl] Create dir and links for a given dir.

#!/usr/bin/perl
#written by vaibhav gupta
#Creates a new directory for a given directory and creates links for files.
$dir = $ARGV[0];
&usages unless $dir ;
©
sub usages {
        print "Usages: <Dirname> \n";
        exit;
}
sub copy {
        @result = `find $dir -type d`;
        $dirname = `echo "$dir"  | rev | cut -d"/" -f 1 | rev`;
        chomp $dirname;
        $desination = "$dirname";
        foreach $d(@result) {
                chomp $d;
                ($a,$b) = split(/$dirname/,$d);
                print "Creating $desination$b\n";
#               print "[$a -- $b]";
                @res = `mkdir -p $desination$b`;
                print @res;
        }
        @result = `find $dir -type f `;
        foreach $d(@result) {
                chomp $d;
                ($a,$b) = split(/$dirname/,$d);
                print "Copying $d\n";
                @res = `ln -s  $d $desination$b`;
                print @res;
        }
}

3 comments:

lowlz said...

http://blog.hackers-cafe.net/2010/04/what-happen-if-you-put-both-str-and.html

ian said...

Awesome post! Thank you so much for sharing. This entire Blog is fantastic!

Palm Pixi Plus Verizon Only Cell Phone with WebOS, Touch Screen said...

good article