Truncate filenames but keep file extensions intact

#! /usr/bin/perl -w
use strict;
use File::Copy;

foreach my $mp3file (@ARGV) {
my $oldname = $mp3file;
$mp3file=~ s/(.{0,27}).*(.mp3)/$1$2/;
if ($oldname eq $mp3file) {
print "Skipping $oldname: name is OK for Mac.
";
next;
}
copy ($oldname, $mp3file) or print "Cannot move $oldname to $mp3file: $!";
print $oldname ." moved to" . $mp3file . "
";
}

source

Leave a Reply