#!/usr/bin/perl use strict; use vars qw($VERSION @PATHS); use Getopt::Std::Strict 'dhvp:a:t'; use Cwd; use Carp; use LEOCHARRE::DEBUG; use File::PathInfo::Ext; $VERSION = sprintf "%d.%02d", q$Revision: 1.1.1.1 $ =~ /(\d+)/g; init(); PATH: for my $abs (@PATHS){ my $f = File::PathInfo::Ext->new($abs) or die; # WHAT IS THE NEW FILENAME my $new_filename; $new_filename .= $opt_p if $opt_p; $new_filename .= $f->filename_only; $new_filename .= $opt_a if $opt_a; $new_filename .= '.'. $f->ext if $f->ext; debug("new filename : $new_filename"); # IS IT THE SAME AS OLD ONE if( $new_filename eq $f->filename ){ warn("same"); next PATH; } my $newpath = $f->abs_loc .'/'.$new_filename; debug("old: $abs, new $newpath"); $opt_t and next PATH; my $newloc = $f->rename( $new_filename ); debug("renamed to $newloc"); } exit; sub usage { qq{$0 - prepend or append filenames OPTIONS -d debug on -h help -v version and exit -p string prepend -a string append, before ext -t test only, don't do it AUTHOR Leo Charre leocharre at cpan dot org SEE ALSO }} sub init { $opt_t and $opt_d = 1; $::DEBUG = 1 if $opt_d; $opt_h and print usage() and exit; $opt_v and print $VERSION and exit; my $abs_path= Cwd::abs_path($_[0]) or die('missing arg or cant resolve'); debug("base path: $abs_path"); @PATHS = reverse split( /\n/, `find '$abs_path'` ); @PATHS and scalar @PATHS or die("nothing here"); }