in reply to Renaming Sub Dir/Files.

Quick question ... What was wrong with the answers provided to you when you posted a few days ago here? All three replies, including my own, addressed your issue - with the exception of the aspect of renaming directories as well. However this could be easily implemented in the code that I provided that used File::Find through the removal of the return unless (-f _); line. eg.

#!d:/perl/bin/perl -w use File::Find; use strict; find ({ 'wanted' => \&renamefile, }, '/path/to/sub/directory'); sub renamefile { my ($dev, $ino, $mode, $nlink, $uid, $gid); return unless (($dev, $ino, $mode, $nlink, $uid, $gid) = lstat($_) +); rename $_, lc($_); }

 

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

Replies are listed 'Best First'.
Re:x2 Renaming Sub Dir/Files.
by grinder (Bishop) on Dec 17, 2001 at 18:00 UTC
    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';
      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