# perl script to create a script to rename files # input: a series of file names, with parameters for renaming. # # updated: 10/27/2015 $debug = 0; $point = ''; #while () { while (<>) { $debug && print STDERR "line $.: ", $_; chomp; /^#|^$/ && next; if ( /^%(\S+)/ ) { $point = $1; next; } if ( /^(.*)\t(.*)/ ) { $before = $1; $suffix = $2; $before =~ s/^\s+//; $before =~ s/\s+$//; $suffix =~ s/^\s+//; $suffix =~ s/\s+$//; if ($suffix eq '') { print STDERR "ignoring line $.: $_\n"; next; } $dot_suffix = ''; if ( $before =~ /\.\w+$/ ) { #preserve the file extension, e.g. .JPG $dot_suffix= $&; } $after = $point . $suffix . $dot_suffix; $cmd = 'system("ren", "%1", "%2"); die $! if $?;'; $cmd =~ s/%1/$before/; $cmd =~ s/%2/$after/; print $cmd, "\n"; } else { print STDERR "unexpected line $.: $_\n"; } } __DATA__ %JCElk1977_ IMGP1370.JPG Na IMGP1371.JPG Nb IMGP1372.JPG Ea IMGP1373.JPG Eb IMGP1374.JPG Sa IMGP1375.JPG Sb IMGP1376.JPG Wa IMGP1377.JPG Wb