Tuesday, October 25, 2011

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


#!/usr/bin/perl
#written by Sumit
#Creates a new directory for a given directory and creates links for files.
$dir = $ARGV[0];
&usages unless $dir ;
©
sub usages {
        print "Usages: \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;
        }
}

No comments: