reading a list of files

J

john williams

Hi,

I have a list of files:

basename_001.ext
....
basename_1000.ext

I would like to be able to read them one by one, and process each
file, then write the files one by one as:

basename_out_0001.ext
....
basename_out_1000.ext


due to the large number of files, I need this to be automated.

Any help would be appreciated, thanks in advance
John
 
G

Gunnar Hjalmarsson

john said:
I have a list of files:

basename_001.ext
...
basename_1000.ext

I would like to be able to read them one by one, and process each
file, then write the files one by one as:

basename_out_0001.ext
...
basename_out_1000.ext

due to the large number of files, I need this to be automated.

What you want to do is possible, and Perl is a possible programming
language.
Any help would be appreciated,

Help with what? Writing your program for you? No way!

Please study the posting guidelines for this group:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html

I don't know how much Perl you know, but maybe you need to start here:

http://learn.perl.org/
 
T

Tad McClellan

john williams said:
I have a list of files:

basename_001.ext
...
basename_1000.ext

I would like to be able to read them one by one,


perldoc -f opendir
perldoc -f readdir
perldoc -f closedir
perldoc -f glob

and process each
file, then write the files one by one as:


perldoc -f rename
perldoc -f open

basename_out_0001.ext
...
basename_out_1000.ext


See the "s/PATTERN/REPLACEMENT/egimosx" section in:

perldoc perlop
 
G

gumby

Hi,

I have a list of files:

basename_001.ext
...
basename_1000.ext

I would like to be able to read them one by one, and process each
file, then write the files one by one as:

basename_out_0001.ext
...
basename_out_1000.ext


due to the large number of files, I need this to be automated.

Any help would be appreciated, thanks in advance
John

Try this:
my @filesToBeProcessed = <$directoryToBeProcessed/*.ext >
foreach(@filesToBeProcessed)
{
#open each file and do what you need then close the file.
}

Should work for you globs the directory you specify and puts the files
with path into the array. Then step through the array and do what
ever you need to with each file.
 
K

krakle

Hi,

I have a list of files:

basename_001.ext
...
basename_1000.ext

Great.. If all the files are in a single directory throw all the file
names in an array...

my @filenames = </some/path/to/dir/*>;

Then loop through the array and perform whatever functions you want
to...

foreach my $file (@filenames) {
# some yadda perl
}
I would like to be able to read them one by one,

open (FILE, $file) || die $!;
@src = <FILE>;
close (FILE);

-or-


open (FILE, $file) || die $!;
while (<FILE>) {
$src .= $_;
}
close (FILE);

and process each
file,

Process each file as in???
then write the files one by one as:

basename_out_0001.ext
...
basename_out_1000.ext

This is all plain ol' simple Perl...

open (FILE, ">$file") || die $!; # Over write.. use >> to append
print FILE "whatever the hell you want\n";
close (FILE);
due to the large number of files, I need this to be automated.

Automated as in ran on a schedule? cronjob...
Any help would be appreciated, thanks in advance
John

Actually, since this is all very simple you could of done it yourself
if you know basic Perl. Looks like you just wanted someone to write it
for you.
 
T

Tad McClellan

Pinocchio said:
my @filenames = </some/path/to/dir/*>;

Then loop through the array and perform whatever functions you want
to...

foreach my $file (@filenames) {
# some yadda perl
}


@filenames is serving no useful purpose.

foreach my $file ( </some/path/to/dir/*> ) { # Look Ma! No temp vars!
 
K

krakle

Tad McClellan said:
@filenames is serving no useful purpose.

foreach my $file ( </some/path/to/dir/*> ) { # Look Ma! No temp vars!

Yes this is true.
My example was just an idea made in 10 seconds..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top