Finding directory in file list.

M

mihirtr

Hi,
I am using perl's find command to find list of files, sub-directories.
I have storred it in local array. Following how it looks.

find (sub{push @dirList, $File::Find::name},$localdir);

where $localdir is directory from where I want to find list of files,
diretories.
@dirList is array which contains this list.

I want to perform specific function if the element in @dirList is a
file and perform some other function if element is a directory. Is
there a way to distinguish between file and directory in this list?

Thanks.
 
P

Paul Lalli

I want to perform specific function if the element in @dirList is a
file and perform some other function if element is a directory. Is
there a way to distinguish between file and directory in this list?

perldoc -f -X

Paul Lalli
 
J

Joe Smith

find (sub{push @dirList, $File::Find::name},$localdir);

I want to perform specific function if the element in @dirList is a
file and perform some other function if element is a directory. Is
there a way to distinguish between file and directory in this list?

I would make that distinction before putting the name into an array.

use File::Find;
find(sub {push @{-d $_ ? \@dirs : \@files}, $File::Find::name}, $localdir);
print "$_ is a directory\n" foreach @dirs;
print "$_ is not a directory\n" foreach @files;

-Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top