All pastes #83409 Raw Edit

neon

public text v1 · immutable
·published 2006-07-09 19:39 UTC
rendered paste body
#!/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. <name>.wav) set this

open FILE, "<", $name_file;

my ($i,$file) = (0,undef);
while (<FILE>) {
    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";
}