http://www.perlmonks.org?node_id=277935


in reply to Variable numbers of folders...

Something like:

opendir(DIR, $directory) or die "Failed to open $directory: $!"; while (defined($filename = readdir(DIR))) { #Do stuff to each file $filename } closedir(DIR);
You could easily wrap in a foreach block if you have multiple directories specified.

LR

Whip me, Beat me, Make me use Y-ModemG.

Update: Also, I might add, Learning Perl and Perl Cookbook are invaluable resources to have on hand.

Replies are listed 'Best First'.
Re: Re: Variable numbers of folders...
by bioinformatics (Friar) on Jul 28, 2003 at 17:39 UTC
    I have tried to implement your suggested code into the program, but have found it isn't workig very well. Apparently, it is unable to open the directory. This could be because I'm not entering the name in a readable form, but I'm not sure. Here's where I'm at:
    #! usr/local/bin/perl print STDOUT "Hello\!\n"; print STDOUT "This program will take a folder of Affymetrix text files + and put\n"; print STDOUT "their signal data in a format useful for Cyber-T\.\n"; print STDOUT "Please enter the name and location of the directory to p +arse\:\n"; $directory=<STDIN>; open (OUTPUTFILE,">data.csv"); opendir(DIR, "$directory") or die "Failed to open $directory: $!"; while (defined(@filename = readdir(DIR))) { @spliced_data=splice(@filename, 0, 15); foreach $_(@filename) { ($a, $b, $c, $d, $e, $f)=split(/\t/); push(@final_data, "$d\n");} print OUTPUTFILE "@final_data"; } closedir(DIR);
    Thanks for your help!!