ACK... all beginners should learn to:

use strict;
use warnings;

and what these two lines mean... but for now if this is your first time
scripting in perl, write the program without these two lines at the top.
ONCE your script is finished and works, add this two lines in a copy of the
script and understand all the errors.

I wish I knew this when I started.

> -----Original Message-----
> From: Bryan R Harris [mailto:[EMAIL PROTECTED]]
> Sent: Friday, June 07, 2002 1:41 PM
> To: [EMAIL PROTECTED]
> Subject: renaming all files in a directory
> 
> 
> 
> Here's a script that does something different, but that you 
> may be able to
> cannibalize.  (Be aware that I've cannibalized this from a 
> script by Larry
> Wall with some customizations thanks to some folks on the 
> list...  It isn't
> mine by any means.)
> 
> - B
> 
> 
> #!/usr/bin/perl -w
> #
> # Batch file renaming
> # Usage:  rename match-expr replace-expr [filenames]
> 
> $match = shift || die("Usage: rename match-expr replace-expr 
> [filenames]
> -- example: rename txt html *.txt\n");
> $replace = shift || die("Usage: rename match-expr 
> replace-expr [filenames]
> -- example: rename txt html *.txt\n");
> 
> # handle lack of file arguments
> if (!@ARGV) {
>   @ARGV = <STDIN>;
>   chomp(@ARGV);
> }
> 
> foreach $_ (@ARGV) {
>   $old_name = $_;
> 
>   if (s/$match/qq(qq($replace))/gee) {
>     print "$old_name --> $_\n";
> 
>     if (-e $_) {print "-> WARNING:  $old_name not renamed because $_
> already exists\n";}
>     else {rename($old_name, $_) unless $old_name eq $_;}
>   }
> }
> 
> exit (0);
> 
> 
> __________________
> 
> 
> All right, first off I'm a total perl newbie (about 2 days now) and am
> looking for some resources on how to do a few things. 
> Resources, meaning,
> don't tell me how to write the script just point me in the 
> right direction
> of where to start. Also this may be an easy thing to do but 
> remember I'm
> still learning.
> 
> So heres what I'm trying to do, I have a few folders with 
> about 50-100 mp3s
> that I want to go threw and rename each file. Well going 
> threw selecting
> them and then renaming gets rather boring so I'm wanting to 
> write a perl
> script that will do this for me. Something like:
> 
> you specify the folder name
> it opens that folder
> gets the first file
> prints how many files are left
> prints the file name
> asks for new name
> renames file
> gets next filename
> then repeats
> 
> So what I figure, I'll use a 'for' loop, get the file name, 
> store it in
> $ThisName, get the new file name from $NewName=<>, then 
> $ThisName=$NewName,
> then rename the actual file. To me the logic seems like it 
> would work, but
> as I said, I'm new to perl. Is this the right direction that 
> I need to be
> going? And can someone point me as to where I can find info on getting
> filenames from folders then writing new names. Thanks for the help!
> 
> jeffh
> 
> 
> 
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 

----------------------------------------------------------------------------
--------------------
The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to