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

Re: [MacPerl] opening files in afolder



you could also simply append the dir path to the file name on the open:

open(IN, "$myFOLDER:$file") or die ("could not open file $myFOLDER:$file");

you also might wish to change the die portion to print out the error i.e.:


die ("could not open file $myFOLDER:$file : $!");


have fun.

-joshua



On 12/16/99 at 1:48 PM, schinder@pobox.com (Paul Schinder) wrote:

> At 10:32 AM -0800 12/16/99, george rosenberg wrote:
> >Dear MacPerl Experts'
> >
> >i'm trying to read the contents of files in a folder and add it to a single
> >file.
> >
> >i'm able to read the file names in the folder
> >
> >but i can not  read  the contents of the files.
> >
> >it appears  that i am at the wrong dir level.
> 
> 
> Well, then, move to the right dir level with chdir.  Your problem is 
> a common one.  opendir() and readdir() do *not* move you into the 
> directory they are reading, and only return file names, not full 
> paths to the files.  So you need a chdir:
> 
> >
> >if i move a file out of its folder i can read it!
> >
> >here is my code:
> >
> >#!perl
> >
> >print ("What is the name of your folder?   ");
> >
> >$myFOLDER = <STDIN> ;
> >chomp($myFOLDER);
> >
> >print ("you picked folder $myFOLDER \n");
> >
> >open(mydata, "+>fas_seq") or die ('Could not make file');
> >
> >opendir(DIR, "$myFOLDER") or die " could not open $myFOLDER";
> >@files = readdir(DIR);
> >closedir(DIR);
> 
> chdir($myFOLDER) or die "Unable to chdir";
> 
> >foreach $file (@files) {
> >        print("$file\n");
> >        print mydata (">$file\n");
> >
> > open(IN, "$file") or die ("could not open file $file");
> >
> > while( $_ = <IN> ){
> >
> >     print "$_";
> >     print mydata "$_";
> > }
> >
> > close(IN);
> >
> >   }
> >
> >close(mydata);
> >
> >here is the error:
> >
> ># could not open file 09 R2S3-REV, <STDIN> chunk 1.
> >
> >any advise?
> >
> >thank you very much.
> >



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