For Programmers: Free Programming Magazines  


Home > Archive > PERL Programming > October 2007 > Having problems reading multiple files









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Having problems reading multiple files
Clemens

2007-10-05, 8:12 pm

Hi all,
I am really having a tough time writing a perl script that will read all the files in a directory and transfer them to another directory on my computer. Please, could anyone tell me what is likely wrong with the code or help me with a better one. I am just a day old using perl. Thanks for your help.

#!/usr/local/bin/perl -w

$forcefiles="/Users/agboma/Desktop/TEST/TEST_DAILY_WB/forcing/";

opendir(FORCING, $forcefiles) || die("Cannot open directory");

@thefiles=grep !/^\.\.?$/,readdir(FORCING);

foreach $dataset (@thefiles) {
print "$dataset\n";

open(FILE,$dataset) ||die("Could not open $dataset\n");
open(OUTFILE,">/Users/agboma/Desktop/perl_learn/$dataset") ||die("Could not open for output $dataset\n");

$line=<FILE>;

while ($line ne "") {
print OUTFILE($line);
$line=<FILE>;

}

}
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com