[pm-h] Meeting Reminder

Mike Flannigan mikeflan at earthlink.net
Tue Feb 14 05:31:27 PST 2006


The script below works fine, I think, but I've only run it twice.
I'm only posting it to see if anybody has any comments
about trivial things that may be wrong with it.  Especially
the "local" statement in MAIN.  I suspect I don't have
that quite correct.

The main recursive routine was obtained from others
long ago.  I now use it for many things - this being
the file name shortening routine.  99% of my scripts
have 'use warnings' and 'use strict', but this one doesn't.
I never took the time to convert it and I seem to get
by modifying it without these pragmas in place.

This script is kinda Windows specific, so those on
Unix may not choose to fool with it.

I won't be at the meeting tonight.


Mike


#
#
# This perl script renames files in the 'C:/Copy2/'
# directory and any subdirectories whose filename
# exceeds the length specificied by $sizemax.
#
# It appends a 6 digit number to the renamed files
# and outputs a list of the renamed files to the screen.
# Just run it with no arguments.
#
#
use English;
use warnings;

print "\n";

sub search_dir
{
        local ( $dirname ) = @_;
        local ( @entries , $entry , $path , @dirs_list , $dircount , @files );

        if ( ! opendir(DIR,$dirname) ) {
                print STDERR "opendir failed for \"$dirname\" : $!\n";
                return 0;
        } # IF
        @entries = readdir DIR;
        closedir DIR;

        @dirs_list = ();
        @files = ();
        $dircount = 0;
        foreach $entry ( @entries ) {
                next if ($entry =~ /\.sys/);
                if ( $entry eq "." || $entry eq ".." ) {
                        next;
                } # IF
                $path = sprintf "%s\\%s",$dirname,$entry;
                if ( -d $path && $entry ne "." && $entry ne ".." ) {
                        $dircount += 1;
                        push(@dirs_list,$entry);
                } # IF
                else {
                        $path =~ s#C:/Copy2/\\#C:\\Copy2\\#i;
                        $path =~ m#(C:\\Copy2\\.*\\)(.*)#i;
                        $pathren = $1 if ($1);
                        $filename = $2 if ($2);
                        if (length $filename > $sizemax) {
                            $countnum++;
                            $countnum = sprintf("%06d", $countnum);
                            $len = $sizemax - 10;
                            ($filenameren = $filename) =~
s/^(.{$len}).*(\..{3})$/$1$countnum$2/;
       $renfull = $pathren . $filenameren;
                            rename $path, $renfull;
                            push
@files,("Renamed\n".$filename."\nto\n".$filenameren."\n");
                        }

#                        push @files,($filename.$space." : ".$size) if ($sizecomp
> $sizemax);
                } # ELSE
        } # FOREACH
        if ( 0 < @files ) {
                print "\n";
                foreach ( @files ) {
                        print "$_\n";
                } # FOREACH
        } # IF
        foreach $entry ( @dirs_list ) {
                $dircount += &search_dir($dirname."\\".$entry);
        } # FOREACH;
        return $dircount;
} # end of search_dir

MAIN:
{
#        open DIROUT, ">C:/Copy2/README - File Listing.txt" or die "$0: open
README - File Listing.txt: $!";
        local ( $dirname , $count );
        $dirname = 'C:/Copy2/';

        $sizemax = 60;
        $sizemax += 4;

        $countnum = 0;

#        print  "Directories under \"$dirname\"\n";
        $count = &search_dir($dirname);
        print "\n";
        print  "\n$count total directories\n";
        exit 0;
} # end of MAIN


__END__


"G. Wade Johnson" wrote:

> Just the monthly reminder about tomorrow's meeting. We'd love to have any you
> willing(and able) to spend a couple of hours on Valentine's Day at HAL-PC
> headquarters.
>
> G. Wade
> --
> "And so it begins"                                -- Ambassador Kosh
> _______________________________________________
> Houston mailing list
> Houston at pm.org
> http://mail.pm.org/mailman/listinfo/houston



More information about the Houston mailing list