Posted By

noah on 07/03/07


Tagged

regex file mac filter name rename old


Versions (?)

Truncate filenames but keep file extensions intact


 / Published in: Perl
 

  1. #! /usr/bin/perl -w
  2. use strict;
  3. use File::Copy;
  4.  
  5. foreach my $mp3file (@ARGV) {
  6. my $oldname = $mp3file;
  7. $mp3file=~ s/(.{0,27}).*(.mp3)/$1$2/;
  8. if ($oldname eq $mp3file) {
  9. print "Skipping $oldname: name is OK for Mac.\n";
  10. next;
  11. }
  12. copy ($oldname, $mp3file) or print "Cannot move $oldname to $mp3file: $!";
  13. print $oldname ." moved to" . $mp3file . "\n";
  14. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: jkramer on January 30, 2008

This is an approach to do the same thing in ZSH: for foo in *; [[ $#foo -gt 31 ]] && mv "$foo" "${${foo:r}[1,27]}.${foo:e}"

You need to login to post a comment.