Another perl solution (was Re: moving upper case names to lower case)
Randal Schwartz
merlyn at iwarp.intel.com
Thu Aug 24 04:20:02 AEST 1989
In article <111 at crdos1.crd.ge.COM>, davidsen at crdos1 (Wm E Davidsen Jr) writes:
|
| In ksh you can do it using the uppercase attribute (I realize we don't
| all use ksh yet).
|
| $ typeset -u ucase
| $ for file in *[a-z]*
| > do ucase=${file}
| > if [ ! -f $ucase ]
| > then mv ${file} ${ucase}
| > else echo "Can't move ${file}"
| > fi
| >done
|
| ksh takes most of the pain out of it, although you may find typing in the
| C program easier. If you have ksh you can put this in as a macro.
OK, here we go again. Presuming the task is to take all of the filenames in
the current directory that contain at least one uppercase character and
make the names lowercase:
################################################## cut here
#!/usr/bin/perl
for $uc (<*>) {
($lc = $uc) =~ y/A-Z/a-z/;
next if ($lc eq $uc) || -e $lc;
print "renaming $uc to $lc...";
(print "done\n"),next if rename($uc, $lc);
print "failed: $!\n";
}
################################################## cut here
Enjoy.
--
/== Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ====\
| on contract to Intel, Hillsboro, Oregon, USA |
| merlyn at iwarp.intel.com ...!uunet!iwarp.intel.com!merlyn |
\== Cute Quote: "Welcome to Oregon... Home of the California Raisins!" ==/
More information about the Comp.unix.questions
mailing list