[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Stupid unix




> Is there a simple way to change all filenames in a directory so they
> are lowercase?

1> cat /usr/local/bin/rename
#!/usr/bin/perl -Tw

use locale;

# usage: rename perlexp [files]

($op = shift) || die "Usage: $0 perlexp [filenames]\n";
if (!@ARGV) {
  @ARGV = <STDIN>;
  chop(@ARGV);
}

$op =~ m/(.*)/; $op = $1;       # Un-taint $op

for (@ARGV) {
  $old = $_;
  eval $op;
  die $@ if $@;
  $new = $_;
  next if $old eq $new;
  next if -e $new;
  $old =~ m/(.*)/; $old = $1; # Un-taint $old
  $new =~ m/(.*)/; $new = $1; # Un-taint $new
  rename($old,$new) || die "$0: cannot rename $old to $new: $!\n";
}

1> rename "y/A-Z/a-z/" *    # lowercase all files
1> rename "s/.jpeg/.jpg/"   # change jpeg to jpg

This is fun if you know perl :-)

-- 
"i'm working on it"


--  
Unsubscribe?  mail -s unsubscribe debian-user-request@lists.debian.org < /dev/null


Reply to: