#!perl # # fixlength.pl # Script to browse a file path (for hudson jobs)and find "target" # directories and shorten the pathname by renaming several common # directory names dir /s /b Zz* # $File::Find::dir = /some/path/ # $_ = foo.ext # $File::Find::name = /some/path/foo.ext # use strict; use warnings; use File::Find; #used to traverse a directory tree my $count; my $char; my @pathname; # open (FILE, "<$file") or die "Can't open $file: $!"; my $directory = "H:/softwaredistribution/hudson/jobs/"; finddepth(\&process_file, $directory); #---------------------------------------------------------------- # Sub Routines start here #---------------------------------------------------------------- sub process_file{ foreach (my $dir = $File::Find::dir){ my $dir1=$File::Find::name; if (($_ ne "\.")&&($_ ne "\..")){ print "Dir is : $File::Find::dir \n file is :$_ \n and fullpathname is : $File::Find::name \n"; my %rephash=("target"=>"t", "checkout"=>"co", "was6-maven-plugin"=>"w6","SNAPSHOT"=>"S"); my @keys = %rephash; my @value = %rephash; foreach my $key (sort keys %rephash){ if ($dir1=~m/$key$/) { my $olddirname=$dir1; $_=$dir1; # s/$key/$rephash{$key}/g; my $newname=$rephash{$key}; print "Command is H:; cd $olddirname; cd ..; move /Y $olddirname $newname \n"; `H:; cd $olddirname; cd ..; move /Y $olddirname $newname` or die "Can't move $olddirname $newname: $!"; } } } } }