in reply to Re: Renaming Sub Dir/Files.
in thread Renaming Sub Dir/Files.

That should read
rename $_, lc($_) or warn "Could not rename $_ to @{[lc($_)]}: $!\ +n";

In case the target filename already exists in the directory (especially if case-sensitive filesystems are involved). Or warn instead of die. Or break lc($_) out into a variable to avoid the code interpolation. Whatever.

--
g r i n d e r
just another bofh

print@_{sort keys %_},$/if%_=split//,'= & *a?b:e\f/h^h!j+n,o@o;r$s-t%t#u';

Replies are listed 'Best First'.
Re: Re:x2 Renaming Sub Dir/Files.
by rob_au (Abbot) on Dec 18, 2001 at 03:46 UTC
    Excellent point grinder++ ... Thanks for the pick-up

     

    perl -e 's&&rob@cowsnet.com.au&&&split/[@.]/&&s&.com.&_&&&print'

      system("clear"); if($ARGV[0] eq "" || $ARGV[0] eq "--help" || $ARGV[0] eq "?" || $ARGV[ +0] eq "-h") { usage(); exit; } if($ARGV[1] eq "" || $ARGV[1] eq "--help" || $ARGV[1] eq "?" || $ARGV[ +1] eq "-h") { usage(); exit; } if($ARGV[2] eq "" || $ARGV[2] eq "--help" || $ARGV[2] eq "?" || $ARGV[ +2] eq "-h") { usage(); exit; } $path = $ARGV[0]; $outputf = $ARGV[1]; $get_subs = $ARGV[2]; open(OUT, ">".$outputf); ##Open Output getfiles($path, $get_subs); close(OUT); exit; ###Sub Routines sub getfiles { my ($path, @files, $fname, $get_subs); $path = @_[0]; $get_subs = @_[1]; opendir(DIR,$path); @files = readdir(DIR); closedir(DIR); $ct = 0; foreach $fname (@files) { my ($full_path, $c_full_path, $p_full_path, $dir_full_path); $full_path = sprintf("%s%s", $path, $fname); $c_full_path .= $path . "."; $p_full_path .= $path . ".."; # print "\n\nSTART:\nFULL PATH: $full_path\n"; # print "\nC_FULL PATH: $c_full_path\n"; # print "P_FULL PATH: $p_full_path\n"; # print "\nOriginal Path: $path\nOrig Fname: $fname\n"; # print "New Path: $path\nNew Fname: $new_fname\n\n"; if($full_path eq $c_full_path) { print "Skip \"CUR:$full_path\"\n" +; next; } # skip cur dir if($full_path eq $p_full_path) { print "Skip \"PAR:$full_path\"\n" +; next; } # skip par dir ($new_path, $new_fname) = &changename($path, $fname, $outputf); if($get_subs eq "1") { if(-d $full_path) # dir find { $dir_full_path .= $full_path . "/"; # print "\nDIRECTORY: $full_path\n"; # print "DIREC: $dir_full_path\n"; getfiles($dir_full_path); next; } } } } sub changename { my ($path, $fname, $new_path, $new_fname, $full_path, $new_full_path +); my ($full_path, $c_full_path, $p_full_path); $path = @_[0]; $fname = @_[1]; $full_path = sprintf("%s%s", $path, $fname); $new_fname = lc($fname); $new_full_path = sprintf("%s%s", $path, $new_fname); #print "\n\nSTART:\nFULL PATH: $full_path\n"; #print "\nC_FULL PATH: $c_full_path\n"; #print "P_FULL PATH: $p_full_path\n"; #print "\nOriginal Path: $path\nOrig Fname: $fname\n"; #print "New Path: $path\nNew Fname: $new_fname\n\n"; rename($full_path, $new_full_path); { print OUT "C: \"$full_path\" -> \"$new_full_path\"\n"; } } sub usage { print << 'EOT'; SYNTAX: perl case.pl path outputf subs USAGE: Take a directory/sub dir and convert all caps/single to lowerca +se Notes: 1. files/subs either "0" or "1" -0 = current files in direc -1 = all current file and file in subdirs ex "./case.pl /home/joeh out 1" EOT } --Thankx for all u'r Help --Joe