Gossamer Forum
Home : General : Perl Programming :

READDIR not working?

Quote Reply
READDIR not working?
Hi. Anyone got any ideas why 'readdir' doesn't seem to be working for mein this code? Probably missed something really simple... but its driving me mad :(

Code:
print $IN->header();

my $dir = 'C:/Inetpub/wwwroot/accreditation/domain.com/cgi-bin/data';

open DIR, $dir || die $!;

# read all but '.' and '..'
my @dir_contents = grep /[^.]/, readdir DIR;

closedir DIR;

foreach (@dir_contents) {

print "File: $_ <BR>";

}

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] READDIR not working? In reply to
Readdir works but you need to use it on a directory filehandle:

Code:
opendir(DIR, $some_dir) || die "can't opendir $some_dir: $!";

~Charlie

[edit]
Ooops: http://www.perldoc.com/...od/func/opendir.html

I guess you need to use it with a DIRHANDLE which is different froma filehandle.
[/edit]

Last edited by:

Chaz: Nov 19, 2003, 9:12 AM
Quote Reply
Re: [Chaz] READDIR not working? In reply to
Mmmm...I'm confused :/ I now have;

Code:
print $IN->header();

my $dir = 'C:/Inetpub/wwwroot/';

opendir DIR, $dir or die "Could not opendir $dir; Reason: $!";

my @files = grep !/^\.\.?$/ => readdir DIR;

closedir DIR;

foreach (@files) {

print "File: $_ <BR>";

}

Unsure

TIA

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] READDIR not working? In reply to
Got it! Stupid old me had a | instead of / in the real path (I edited the one for the post).... man I feel stupid!

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] READDIR not working? In reply to
Quote:
man I feel stupid!

Don't feel alone, it happens to us all :) (and quite often for me!)

~Charlie
Quote Reply
Re: [Andy] READDIR not working? In reply to
Just a quick mention that your precedence is incorrect in your original example..

Code:
open DIR, $dir || die $!;


...is equivalent to:

Code:
open DIR, ($dir || die $!);


Chaz corrected this in her example.