Unless $folder is the current directory, you will either need to prepend it
to the name of the directory you are checking or cd to that directory.

i.e.

foreach $Name (@all_files) {
  print $Name;
  if( -d "$folder/$Name" ) {
    print $Name;
  }
}
----- Original Message -----
From: "Caroline Warnock" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, January 16, 2002 11:04 AM
Subject: Reading Directories


> 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
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to