#!/usr/bin/perl use strict; use warnings; my $workdir = "/tmp"; # Where the .wav files are located my $outdir = "/tmp"; # Where to put the renamed files my $name_file = "/tmp/names.txt"; # text file with file names in it (one per newline) my $file_ext = ".wav"; # If the names in $name_file doesn't have filename extensions in them (ie. .wav) set this open FILE, "<", $name_file; my ($i,$file) = (0,undef); while () { chomp; $i++; $file = -f "$workdir/$i$file_ext" ? "$i$file_ext" : "0$i$file_ext"; if (! -f "$workdir/$file") { print "$workdir/$file: No such file\n"; last; } print "Renaming: $workdir/$file ..."; rename "$workdir/$file", "$outdir/$_$file_ext" or die "Can't rename $workdir/$file to $outdir/$_$file_ext: $!"; print "done\n"; }