Changing upper-case filenames to lower-case

Chip Salzenberg chip at ateng.com
Thu Nov 30 12:15:28 AEST 1989


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

I'd think that "<*>", which runs "/bin/sh echo", should be avoided.
Rather, you'd be better off reading the directory directly...

	eval 'exec /bin/perl -S $0 ${1+"$@"}'
		if 0;
	
	# Get all the files' names
	opendir(DOT,".") || die "$0: can't read \".\": $!\n";
	@F = readdir(DOT);
	closedir(DOT);
	@F = sort @F;
	
	# Rename some of them
	foreach $f (@F) {
		next if $f =~ /^\./;    # Don't mess with invisible files
		($_ = $f) =~ y/A-Z/a-z/;
		rename($f, $_) unless $f eq $_;
	}

Yet Another Perl Hacker,
-- 
You may redistribute this article only to those who may freely do likewise.
Chip Salzenberg at A T Engineering;  <chip at ateng.com> or <uunet!ateng!chip>
	  "The Usenet, in a very real sense, does not exist."



More information about the Comp.unix.questions mailing list