Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Finding directory in file list.

Reply
Thread Tools

Finding directory in file list.

 
 
mihirtr@gmail.com
Guest
Posts: n/a
 
      12-26-2006
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.

 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      12-26-2006
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

 
Reply With Quote
 
 
 
 
Joe Smith
Guest
Posts: n/a
 
      12-27-2006
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding the local directory of a file in the python path are Dogue Python 1 05-18-2011 01:53 AM
System.IO.Directory.GetDirectories() and System.IO.Directory.GetFiles() are not returning the specified directory Nathan Sokalski ASP .Net 2 09-06-2007 03:58 PM
finding the last file created in a directory Petr Man Python 0 06-30-2006 12:43 PM
finding the directory a .jar file was launched from steve Java 5 06-13-2005 07:20 AM
Problem finding directory ** File dir = new File(URL+aFile_to_add); vivienne wykes Java 1 08-03-2004 04:12 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57