Open Directories
Anonymous Monk
created: 2006-02-03 09:09:22
Hi Monks!
I am trying to process multiple *.txt files inside various directories, can I use something like the sample code:
my $local_list;

my @local_list = (
	
"c:/progra~1/apache~1/apache2/htdocs/a_1",	
"c:/progra~1/apache~1/apache2/htdocs/a_2",
"c:/progra~1/apache~1/apache2/htdocs/a_3",
"c:/progra~1/apache~1/apache2/htdocs/a_4",
"c:/progra~1/apache~1/apache2/htdocs/a_5",
"c:/progra~1/apache~1/apache2/htdocs/a_6"

);
#@data = qw(List Of Locations Here);
    print join("
", @local_list); #Open directory and search for *.TXT files my(@dircontent, $filesize, $file); opendir DIR, "@local_list"; @dircontent = grep { /\.txt$/ } readdir(DIR); ...do stuff..

The question would be like how to open multiple directories at once from a list of path to all the location I need it open.
Thanks 4 the Help!
Re: Open Directories
created: 2006-02-03 09:32:09
The question would be like how to open multiple directories at once from a list of path to all the location I need it open.

I have absolutely no idea what you are trying to say. Me not speaking english native can be the cause here, but could you try to put more effort into describing your problem? As I believe I understood you, you'd just want a loop around the open/read/close of each directory in the list.

Ordinary morality is for ordinary people. -- Aleister Crowley
Re^2: Open Directories
created: 2006-02-03 09:42:39
Sorry, it's just an array like the one on the code with all the path to the locations where I would like to open and parse some text files in these directories.
Re^3: Open Directories
created: 2006-02-03 12:09:29
So, you want a list of all matching files from all the directories in the list? Then I'd say tirwhan's solution is your way to go.

Ordinary morality is for ordinary people. -- Aleister Crowley
Re: Open Directories
created: 2006-02-03 09:32:29

You can only open one directory per opendir call, so process them one after the other:

#Open directory and search for *.TXT files
my(@dircontent, $filesize, $file);
for my $path(@local_list) {
  opendir my $dirh,$path or die "Can't open $path";
  push (@dircontent,grep { /\.txt$/ } readdir($dirh));
  closedir($dirh) or die "Can't close $path";
}
If you need the directory handles stored for later processing, use a hash:
my %dirh;
for my $path(@local_list) {
  opendir $dirh{$path},$path or die "Can't open $path";
  # ...
}

All dogma is stupid.
Re: Open Directories
created: 2006-02-03 09:39:00
perl -e '$\="\n";print while '
Re: Open Directories
created: 2006-02-03 11:01:11

If you really need to open and read those directories at the "same time" you should use threads or fork children process to do that.

Alceu Rodrigues de Freitas Junior
---------------------------------
"You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill

perlmonks.org content © perlmonks.org and Anonymous Monk, glasswalk3r, phaylon, smokemachine, tirwhan

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03