* David Nelson <[EMAIL PROTECTED]> [010305 18:12]:
> I have netatalk installed on my LM 7.2 system so that I can share files with
> our MacOS system. Problem is files with names containing more than 31
> characters don't show up to the Macs. To fix this I need a tool that can trim
> down the file name while preserving the file extension. For example I need
> something that would turn "everclear-so much for the afterglow.mp3" into
> "everclear-so much for the.mp3" not "everclear-so much for the". On the Mac I
> use AppleScript if I need to do batch file renaming. I suppose on Linux this
> type of thing is done with shell scripts? Am I on the right track? Anyone
> have such a script they would be willing to share? Good books on learning
> shell scripting?
Try this. I tested it and it seems to work, but of course copy your
files into a temporary directory first:
#!/usr/bin/perl -w
# name this file to maxlen
# move it into your path
# chmod 775 to make it executable
use strict;
my $syntax = "Usage: maxlen 28 *.mp3\n";
my $len = shift or die $syntax;
my $was = ""; # original file.ext
my $filecount = 0; # files renamed
my $base = ''; # everything before ext
my $ext = ''; # .ext
die $syntax unless $len =~ /^\d+$/;
for (@ARGV) {
chomp; # in case newline
next if -d $_; # skip directories
if ( /^(.+)(\.[^.]+)$/ ) {
# found base.ext
$base = $1;
$ext = $2;
} else {
# no ext, just shorten
$base = $_;
}
next if length $base <= $len;
$was = $_; # save original filename
$base = substr($base,0,$len);
if ( -f "$base$ext" ) {
print "Did not rename $was to $base$ext";
print " because it already exists.\n";
} else {
if ( rename($was, "$base$ext") ) {
$filecount++;
} else {
print "Error renaming $was to $base$ext\n";
}
}
};
if ( $filecount ) {
print "Renamed $filecount file";
print "s" if $filecount > 1;
print "\n";
};
--
Jan Wilson _/*]; [EMAIL PROTECTED]
Corozal Community College | |:' Corozal Junior College
Corozal Town, Belize | /' Central America
Visit our Corozal site |_/ http://www.corozal.com