[NMLUG] cool perl script?

nmlug@swcp.com nmlug@swcp.com
Tue, 13 Nov 2001 16:06:44 -0700 (MST)


I haven't actually tried it, but I wonder if some variation of:

find . -depth | perl -nle \
'/(.*)\/(.*?)$/; ($a,$b)=($1,$2); $b=~s/[^a-z0-9_\.]/_/isg; $b=lc($b); \
$c="$a/$b"; unless ($c eq $_) {print "mv $_ $c"}'

piped to sh would do the same thing?

--
Sincerely, Sarang (sarang@sarangworld.com)
AOL Instant Messenger ID: JavaMath

On 13 Nov 2001, Eric Krieger wrote:

> Date: 13 Nov 2001 10:22:10 -0700
> From: Eric Krieger <yamato@swcp.com>
> Reply-To: nmlug@swcp.com
> To: nmlug@swcp.com
> Subject: [NMLUG] cool perl script?
>
> 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
> -----------------------------------------------------
>
>

------------------------------------------------------
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
-----------------------------------------------------