Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > find help

Reply
Thread Tools

find help

 
 
jammer
Guest
Posts: n/a
 
      09-30-2008
I am trying to find all directories of a certain name.
I use `find . -name certainName -type d`;
I do not need to go below the current directory.
I tried adding -depth 1 to find but that doesn't do what I want.

Is there a 100% perl way of doing what I need?

I read the documentation for File::Find and it doesn't seem to only
find directories.
 
Reply With Quote
 
 
 
 
Vicky Conlan
Guest
Posts: n/a
 
      09-30-2008
According to <(E-Mail Removed)>:
>I am trying to find all directories of a certain name.
>I use `find . -name certainName -type d`;
>I do not need to go below the current directory.
>I tried adding -depth 1 to find but that doesn't do what I want.
>
>Is there a 100% perl way of doing what I need?
>
>I read the documentation for File::Find and it doesn't seem to only
>find directories.


Does this do what you want?

opendir(DIR,".");
@dirs = grep {/certainName/ && -d $_} readdir(DIR);
print Dumper(\@dirs)'
--
 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      09-30-2008
jammer <(E-Mail Removed)> wrote:
>I am trying to find all directories of a certain name.
>I use `find . -name certainName -type d`;
>I do not need to go below the current directory.
>I tried adding -depth 1 to find but that doesn't do what I want.
>
>Is there a 100% perl way of doing what I need?
>
>I read the documentation for File::Find and it doesn't seem to only
>find directories.


It will find whatever you tell it to find in the wanted() function.

However, because you seem to be interested in the names of the
directories in the current directory only. Therefore File::Find is
really overkill.
Just opendir(), readdir() in list context, and then grep(-d) on the
listing.

jue

 
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
How to exclude action of Find::Find::find in subdirectories withknown names? vdvorkin Perl Misc 3 02-14-2011 05:28 AM
How to exclude action of Find::Find::find in subdirectories withknown names? vdvorkin Perl Misc 0 02-10-2011 05:18 PM
help on find over find Mauricio Alcayaga Ruby 2 01-21-2011 08:37 PM
Find.find does not find orphaned links? Wybo Dekker Ruby 1 11-15-2005 02:50 PM
Find::Find Dan Jones Perl 1 10-08-2004 09:14 AM



Advertisments