Changing upper-case filenames to lower-case

Dave Lawrence tale at cs.rpi.edu
Thu Dec 7 20:26:39 AEST 1989


According to merlyn at iwarp.intel.com (Randal Schwartz):
RandalL> perl -e 'for$f(<*>){($_=$f)=~y/A-Z/a-z/;rename($f,$_)unless$f eq$_;}'

In article <25747F32.4268 at ateng.com> chip at ateng.com (Chip Salzenberg) writes:
Chip> I'd think that "<*>", which runs "/bin/sh echo", should be avoided.
Chip> [much longer solution deleted]
 
In <1989Dec7.020047.8178 at sq.sq.com> lee at sq.sq.com (Liam R. E. Quin) writes:
Liam> Er, am I missing something?

Yes.

Liam> for i in *
Liam> do
Liam>   mv $i `echo $i | tr '[A-Z]' '[a-z]'`
Liam> done
 
Fine.  I have a directory with 400 files in it that I want to convert
this way.  You just soaked up 800 processes.  The perl solution used
two (that is, as long as Chip is right about the /bin/sh, and I don't
have any reason to doubt him).  Depending on the limitations of your
sh, too, the * expansion might break in both your version and the
original perl example.

Liam> Is the issue really minimising the number of characters typed,
Liam> getting the most easily understood solution, or simply doing as
Liam> much as possible in perl?

RandalL offered the perl solution both to continue his presence as the
man who can make perl do anything but buy him dinner and to show an
efficient way of handling multiple files, since perl uses the unlink(2)
call directly.

Chip followed up on RandalL's efficiency offering by not only doing
the unlink() calls from perl, but the reading of the directory file
too.  This puts it into one process, no matter the size of the
directory.

Both RandalL's and Chip's messages were pretty clear about why they
were being offered.

Dave
-- 
   (setq mail '("tale at cs.rpi.edu" "tale at ai.mit.edu" "tale at rpitsmts.bitnet"))



More information about the Comp.unix.questions mailing list