Click to See Complete Forum and Search --> : perl help?


TheLinuxDuck
10-14-2000, 10:12 PM
Ok, here's a perl snippet that will scan for all files in a given dir and recurse through all subdir's. It works great. Except for when you give a wildcard and a partial filename.

If that is the case, and it doesn't find any files in the current dir matching that filename, the search function chokes.

I guess I need to just offer the ability to list what file extensions to rename...


#!/usr/bin/perl -w
use strict;
use File::Find;

my (@newfiles)=();

if($#ARGV>0) {
my ($frontend,@files)=@ARGV;

find (\&search, @files);
rename ($newfiles[$_],$frontend . $newfiles[$_]) for 0..$#newfiles;
print "@newfiles\n";
}
else {
die "Usage: $0 pre-extension filename [filename] [..]\n";
}

sub search
{
push (@newfiles,$File::Find::name) if(!-d);
}


------------------
TheLinuxDuck
Wait... that's a penguin?!?!?
:wq

[This message has been edited by TheLinuxDuck (edited 16 October 2000).]

TheLinuxDuck
10-16-2000, 03:55 PM
Anybody have any optimizations or anything?

------------------
TheLinuxDuck
Wait... that's a penguin?!?!?
:wq

kmj
10-16-2000, 05:00 PM
Ok, here's a perl snippet that will scan for all files in a given dir and recurse through all subdir's. It works great. Except for when you give a wildcard and a partial filename.
If that is the case, and it doesn't find any files in the current dir matching that filename, the search function chokes.


you probably have to glob yourself. there's a glob function, and there's a way to do it with backticks or single quotes or something; I'll try to find the information.

unless you already knew that and I just didn't see it in your program...

takshaka
10-17-2000, 06:39 PM
I'm not exactly sure what you want to do.

But, if you pass a glob on the command line, the shell will expand it into a list of filenames before giving it to the program.

TheLinuxDuck
10-17-2000, 06:44 PM
Originally posted by takshaka:
I'm not exactly sure what you want to do.

But, if you pass a glob on the command line, the shell will expand it into a list of filenames before giving it to the program.

Actually, I figgered out what was going on.. I *just* posted a link to the new code.. if you'd like to take a look, check out this topic: http://www.linuxnewbie.org/ubb/Forum14/HTML/001382.html

Someone in the gen area wanted a file renamer that recursed a dir tree, and prepended an extention to the filename.

This was my attempt.. http://www.linuxnewbie.org/ubb/smile.gif

------------------
TheLinuxDuck
Wait... that's a penguin?!?!?
:wq