[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl-AnyPerl] MacPerl batch file renaming?



Hi All,
I like your book, but I'm sortof new to Perl and certainly new to 
Perl on a Mac. I have what I think should be a relatively simple task 
that I hope MacPerl will be able to handle. I have literally hundreds 
of files with goofed up names that I would like to rename. The 
actions fall into several broad categories. So I'll describe each by 
and example.

1) filename 1  --> filename1
2) filename 1  --> filename_1
3) filename.ext --> filename
4) filename  --> filename.ext

I think I could handle the first one by passing each filename to a 
regular expression searching for the first blank something like "(*) 
([1-9]+)" and then doing a rename to $1$2.

The second example is very simple (I think)
	s/\s/_/;

The third would be
	"(*).*" renaming to $1

The fourth would be
	"(*)" renaming to $1.ext

I see in the book the reserved work "rename(OLDNAME,NEWNAME) which 
looks like it'll do the trick something like this for the first 
example:

	$currentname = "(*) ([1-9]+)";
	$newname = $1$2;
	rename($currentname,$newname);

The thing I don't know how to do is pass a list of filenames to the 
script either by dragging and dropping a folder of bunch of files and 
then how to process the list.

I'm sure I can't be the first person to ask this type of question so 
rather than write the script for me, do you know where I might be 
able to get an example that would point me in the right direction?

TIA,
--John

+-----------------------------------+
|          John McDermon            |
|        john@mcdfamily.com         |
|    http://www.mcdfamily.com       |
+-----------------------------------+

==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-anyperl-request@macperl.org