Sorry Anders, this script doesn't do what I want it to do: differentiate
between files and directories within a directory.

____________________________________________
Steve Gross                          Tel:    (973) 586-8722  x249
IT Manager                           Fax:   (973) 586-0450
Fette America, Inc.


> -----Original Message-----
> From: Anders Holm [mailto:[EMAIL PROTECTED]
> Sent: Friday, June 04, 2004 10:12 AM
> To: Steve Gross
> Cc: '[EMAIL PROTECTED]'
> Subject: Re: Directory Test in Windows?
> 
> 
> 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.
> >  
> 

Reply via email to