#!/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 ); }

In reply to NotSoLong.pl by ichimunki

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.