find help

Discussion in 'Perl Misc' started by jammer, Sep 30, 2008.

  1. jammer

    jammer Guest

    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.
     
    jammer, Sep 30, 2008
    #1
    1. Advertising

  2. jammer

    Vicky Conlan Guest

    According to <>:
    >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)'
    --
     
    Vicky Conlan, Sep 30, 2008
    #2
    1. Advertising

  3. jammer <> 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
     
    Jürgen Exner, Sep 30, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dan Jones

    Find::Find

    Dan Jones, Oct 7, 2004, in forum: Perl
    Replies:
    1
    Views:
    848
    Joe Smith
    Oct 8, 2004
  2. ad
    Replies:
    2
    Views:
    890
  3. Wybo Dekker
    Replies:
    1
    Views:
    395
    Yukihiro Matsumoto
    Nov 15, 2005
  4. vdvorkin
    Replies:
    0
    Views:
    437
    vdvorkin
    Feb 10, 2011
  5. vdvorkin
    Replies:
    3
    Views:
    863
    vdvorkin
    Feb 14, 2011
Loading...

Share This Page