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

Reading Directories

Thread Next
Caroline Warnock
January 16, 2002 08:06
Reading Directories
Message ID:
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/"; 
3	opendir(DEV, $folder);
5	@all_files = readdir(DEV);
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

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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About