in reply to Re^2: rename files
in thread rename files

Adapt as required

#!/usr/bin/perl use strict; use warnings; use Time::Piece; use File::Copy; my $path = '/Users/flieckb/Desktop/'; my $logfile = $path.'whitefiles.txt'; my $tiff = $path.'aero_tiff/'; my $whitefiles = $path.'aero_2push_white/'; my $mybadmatch = '_white.tif'; my $date = localtime->ymd; unless (-d $tiff){ die "$tiff does not exist"; } unless (-d $whitefiles){ die "$whitefiles does not exist"; } chdir( $tiff ) or die "$!"; my @tiff_list = glob "*tif"; my $upload_count = @tiff_list; open FILE, '>>', $logfile or die "Could not open $logfile : $!"; foreach my $file (@tiff_list) { if ( $file =~ /$mybadmatch/i ){ print "$file is white background match\n"; my $old = $tiff.$file; print "Copying $old to $whitefiles\n"; copy($old, $whitefiles) or warn "$!"; print FILE "$date\t$file\t\n"; } else { print "$file :normal production image\n"; } } close FILE; chdir( $whitefiles ) or die "$!"; my @white_list = glob "*tif"; foreach my $old (@white_list) { my $new = $old; if ($new =~ s/white/main/i){ print "Renaming $old to $new\n"; rename($old, $new) or warn "$!"; } }
poj