| Category: | utility scripts |
| Author/Contact Info | x@ichimunki.com |
| Description: | |
#!/usr/bin/perl -w
##################################################
#
# NotSoLong.pl - by ichimunki
#
# hereby released into Public Domain
# use at your own risk! tested on Linux only.
#
# usage: 'notsolong.pl [directory|filename]
# if no argument will use current directory
#
# purpose: recurse through a directory tree
# shortening both filenames and directory names
# to be 31 characters or less, so that they are
# visible via AppleTalk to Macs running pre-OS X
# versions of Mac OS.
#
# will normally just clip the name, but does
# check to make sure the new, shorter name isn't
# already in use. if so, appends numbers until
# it gets a unique name.
#
# does not handle .paths at all, as these are
# normally invisible to Mac OS
#
##################################################
use strict;
use File::Copy;
use File::Basename;
use File::Find;
@ARGV = ('.') unless @ARGV;
finddepth sub
{
if( ( length > 31 ) && -d && !/^\./ )
{
print "D: $_\n";
my $short_name = substr( $_, 0, 31 );
print "d: $short_name\n";
change_name( $_, $short_name );
}
if( ( length > 31 ) && !-d && !/^\./ )
{
print "F: $_\n";
my ($ext) = /.+?(\..+?)$/;
my $short_name = substr( $_, 0, 31 - length($ext) ) . $ext;
print "f: $short_name\n";
change_name( $_, $short_name, $ext );
}
}, @ARGV;
exit;
sub change_name
{
my $old = shift or
die "No too long name: $!";
my $new = shift or
die "No short enough name: $!";
my $ext = shift || undef;
my $counter = 1;
while( stat( $new ) )
{
$counter++;
if( $ext ) #this is a file
{
$new = substr( $new, 0, 31 - length($counter) - length($ext) ) .
$counter .
$ext;
}
else #this is a directory handle
{
$new = substr( $new, 0, 31 - length($counter) ) . $counter;
}
}
print "X: $new\n";
move( $old, $new );
}
|
|
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: NotSoLong.pl
by ncw (Friar) on Aug 12, 2001 at 22:14 UTC | |
by ichimunki (Priest) on Aug 13, 2001 at 04:53 UTC | |
by Anonymous Monk on Oct 24, 2003 at 14:12 UTC |