[Perl] Re: glob/readdir

Pinkhas Nisanov nisanov at netvision.net.il
Mon Aug 27 07:01:12 PDT 2001


Hi,

If you need to take directory content don't use "ls -l",
better way is to use standard perl module "DirHandle"
example:

use DirHandle;

my $dir = "/home/someuser";
my $dh = new DirHandle;
my @direntries = $dh->read( $dir );
foreach my $fileentry ( @direntries )
{
    if( -f "$dir/$fileentry )
    {
        print "$fileentry is file\n";
    }
    elsif( -d "$dir/$fileentry )
    {
        print "$fileentry is directory\n";
    }
    else
    {
        print "$fileentry is something else\n";
    }
}


Pinkhas


----- Original Message ----- 
From: "nothingmuch" <nothingmuch at mac.com>
To: <israel-pm-list at happyfunball.pm.org>; <perl at perl.org.il>
Sent: Monday, August 27, 2001 2:17 PM
Subject: glob/readdir


> i need to be able to tell wether a listed file is a directory or normal 
> file...
> 
> example of what i mean:
> 
> in any shell when you do ls -l it outputs a list... on the leftmost 
> column is the file mode...
> 
> -rwx-r--r-- file name yadda yadda
> drwx-r--r-- directory name yadda yadda
> 
> i need to be able to know the difference within perl...
> -
> to unsubscribe from israel-pm-list, do:
> echo "unsubscribe israel-pm-list" | mail majordomo at hfb.pm.org
> 




More information about the Perl mailing list