Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
#!/usr/bin/perl -w # scribbled by CBAS [ mailto:cbas@screaming3d.com ] # 30/12/2000 # # "One more kick to get me started ..." # - Republica use strict; use subs qw { doDir doFile freakOut }; use vars qw { $from $into $recur $renamed $directories $argument }; freakOut and exit unless @ARGV >= 4; $renamed = 0; $directories = 0; $from = shift @ARGV; $into = shift @ARGV; $recur = shift @ARGV; print <<EOL; Renaming files from "foo$from" to "foo$into" ... EOL for $argument ( @ARGV ) { print "WARNING: \"$argument\" could not be found as a directory.\n +" unless -d $argument and doDir ( $argument ); } print <<EOL; Renamed $renamed file(s) in $directories directories. EOL sub doDir { my ( $dir, $foo, @fools ); $dir = shift; opendir DIR, $dir or return 0; @fools = readdir DIR; closedir DIR; shift @fools; shift @fools; foreach $foo ( @fools ) { if ( $recur and -d "$dir/$foo" ) { doDir ( "$dir/$foo" ); } elsif ( -f "$dir/$foo" and $foo =~ /$from$/ ) { doFile ( "$dir/$foo" ); } } $directories++; return 1; } sub doFile { my ( $file, $temp ); $file = shift; $temp = $file; $file =~ s/(.*)$from$/$1$into/; if ( rename $temp, $file ) { $renamed++ } else { print "couldn't rename $temp: $!" } } sub freakOut { print <<EOL; Usage: $0 from into recur dir [dir [dir ... ] Where: from the file extension you want to change into to what you want to change from recur renaming will happen recursively when set to anything but 0 dir directory that will be traversed by the script Example: $0 .MP3 .mp3 1 . EOL }

In reply to switcher by $CBAS

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2024-04-16 07:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found