#!/usr/bin/perl -ws # by jac, 06/03/2004 use strict; our ( $f, $h, $r, $v ); die 'Usage: lowerextensions [OPTIONS] FILES Lowers the extensions of files. -f forces overwriting of files -h displays help and exits -r recursive -v verbose mode ' if $h; @ARGV || die "lowerextensions: too few arguments Try `lowerextensions' -h for more information. "; for (<@ARGV>) { rename_entry($_); } sub rename_entry { for (@_) { # for each entry if (-f) { # if it's a file if (/\.[^.]*[A-Z][^.]*/) { # if has uppercased extension ( my $new = $_ ) =~ s/\..*?$/lc$&/e; # sets a new name if ( -e $new ) { # checks for new name existance unless ($f) { # unless we're forcing warn "file '$new' exists. Not renaming '$_'.\n"; # don't rename } } if ( rename $_, $new ) { # we try to rename. if sucessfull... print "$_ -> $new\n" if $v; # print if verbose mode } else { # otherwise warn "couldn't rename '$_' to '$new' ($!)\n"; # warn we didn't rename } } } elsif ( -d && $r ) { # if it's a directory chdir $_ or die "can't change to '$_' ($!)\n"; # let's go there for (<*>) { # and for each entry rename_entry($_); # let's rename it } chdir ".."; # and go back to where we were } } } __END__ =head1 NAME I - lowercases extensions =head1 SYNOPSIS I [OPTIONS] FILES =head1 DESCRIPTION I lowercases extensions of files =head1 USAGE lowerextensions [-f] [-h] [-r] [-v] FILES =head1 OPTIONS =head2 -f Force overwriting of files =head2 -h Display help and exit =head2 -r Recursive mode =head2 -v Verbose mode =head1 AUTHOR Jose Alves de Castro, Ecog [at] cpan [dot] org =head1 COPYRIGHT AND LICENSE Copyright 2004 by Jose Alves de Castro This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut