[NMLUG] cool perl script?

Eric Krieger nmlug@swcp.com
13 Nov 2001 10:22:10 -0700


since where on the topic of perl scripts. =)

here's a perl script that i use for remaning mass quanties of mp3s...=)

basically it traverses directories and renames both files and
directories from something like....

Foo Masters

to

foo_masters

enjoy,
eric

------


#!/usr/bin/perl


#chdir ("");

&traverse('.');

sub traverse {
    local($dir) = shift;
    local($path);
    unless (opendir(DIR, $dir)) {
        warn "Can't open $dir\n";
        closedir(DIR);
        return;
    }
    foreach (readdir(DIR)) {
        next if $_ eq '.' || $_ eq '..';
        $path = "$dir/$_";
        if (-d $path ) {
	  &lc;
            &traverse($path);
        }
        elsif (-f _)
        {
          &lc;
        }
    }
    closedir(DIR);
}

sub lc
{           $file = $_;
           $file = "\L$file\E";
           $file =~ s/ /_/g;
           if ($file ne $_)
           {
             print "renamed $_ to $file\n";
             `mv \"$dir/$_\" \"$dir/$file\"`;
           }
	    $path = "$dir/$file";

}

------------------------------------------------------
To UNSUBSCRIBE send a message to nmlug-request@swcp.com
with only the word unsubscribe in the body.  More
information can be found at www.nmlug.org/info.html
-----------------------------------------------------