develooper Front page | perl.beginners | Postings from January 2002

Reading Directories

Thread Next
From:
Caroline Warnock
Date:
January 16, 2002 08:06
Subject:
Reading Directories
Message ID:
3C45A47E.716CCC5@lhr-sys.dhl.com
I'm trying to use the following, in order to be able to print the
names of sub-directories within a directory:

1	$folder = "/home/cwarnock/public_html/staged/DEVELOPMENT/"; 
2
3	opendir(DEV, $folder);
4
5	@all_files = readdir(DEV);
6
7	foreach $Name (@all_files) {
8		print  $Name;
9		if(-d $Name){
10			print "$Name\n"; 
11			}

I know that the directory has at least 4 sub-directories.

The 'print $Name;' on line 8, correctly prints all the sub-directory
and file names as well as '.' and '..'.
However, the 'print "$Name\n";' on line 10 (after the if statement)
only prints '.' and '..'. None of the other 4 directories are
printed.

I have also tried using 'if(-f $Name)' to see if files will be
printed but these do not appear to be being picked up.

Is there any explanation as to why this may be happening.

Thank you for your help.

Caroline Warnock

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About