Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   Finding directory in file list. (http://www.velocityreviews.com/forums/t901188-finding-directory-in-file-list.html)

mihirtr@gmail.com 12-26-2006 05:36 PM

Finding directory in file list.
 
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.


Paul Lalli 12-26-2006 05:38 PM

Re: Finding directory in file list.
 
mihi...@gmail.com wrote:

> 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


Joe Smith 12-27-2006 08:04 AM

Re: Finding directory in file list.
 
mihirtr@gmail.com wrote:

> 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



All times are GMT. The time now is 08:24 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.