find help

J

jammer

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.
 
V

Vicky Conlan

According to said:
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)'
--
 
J

Jürgen Exner

jammer said:
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
 

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,744
Messages
2,569,481
Members
44,900
Latest member
Nell636132

Latest Threads

Top