Hi Steve.

Sorry, reread your mail again there.

You want to match files in a specified directory.

For that purpose you are then matching entries in the directory using
-d. That will match directories, and not files, so a return value of .
or .. would be valid, since that is what you are asking for.

Try using -f instead of -d, and see what you get.

The code snippet I sent in my last mail would iterate over any entry in
a directory if it isn't . or ..

HTH!

//Anders//

On Fri, 2004-06-04 at 14:34, Steve Gross wrote:
> 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.
> > >  
> > 
-- 
Anders Holm

Professional Services Consultant
CriticalPath - Macclesfield - United Kingdom

Support Site:   http://support.criticalpath.net/
Web Site:       http://www.criticalpath.net/


-- 
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