Hi Steve.

Do:

use strict;
use Fcntl;

my $dirname = "D:\\XYZ";
my @directories;

if(opendir(DIR, $dirname)) {

        @directories = grep !/^\.\.?\z/, readdir DIR;
        foreach(@directories) {
                print $_;
                print "\n";
        }
}

The grep statement will match anything which isn't a dot "." or 2 dots
".." .

I'll leave testing for valid directories as an excercise.. ;)

//Anders//

On Fri, 2004-06-04 at 13:13, Steve Gross wrote:
> I'm trying to perform an operation on every file in a directory.  I want to
> skip directories.  I'm using the "-d" file test but it only catches "." and
> "..".  Any ideas?
> Here's the code (most of it out of the Cookbook):
> my $dirname = "D:\\XYZ";
> 
> opendir(DIR, $dirname) or die "can't opendir $dirname: $!";
> 
> while (defined(my $file = readdir(DIR)))
> { 
>     if (-d $file)
>     {
>         print "DIR: $file\n";
>         next;
>     }
>     else 
>     {
> 
>         # do something here
> 
>     }
> 
> }
> 
> 
> ____________________________________________
> Steve Gross                          Tel:    (973) 586-8722  x249
> IT Manager                           Fax:   (973) 586-0450
> Fette America, Inc.
>  


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to