Finding directory in file list.

Discussion in 'Perl Misc' started by mihirtr@gmail.com, Dec 26, 2006.

  1. Guest

    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.
    , Dec 26, 2006
    #1
    1. Advertising

  2. Paul Lalli Guest

    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
    Paul Lalli, Dec 26, 2006
    #2
    1. Advertising

  3. Joe Smith Guest

    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
    Joe Smith, Dec 27, 2006
    #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. vivienne wykes
    Replies:
    1
    Views:
    458
    Andrew Thompson
    Aug 3, 2004
  2. steve
    Replies:
    5
    Views:
    509
    Owen Jacobson
    Jun 13, 2005
  3. Gonnasi
    Replies:
    6
    Views:
    366
    Gonnasi
    Oct 24, 2005
  4. Petr Man
    Replies:
    0
    Views:
    262
    Petr Man
    Jun 30, 2006
  5. are Dogue
    Replies:
    1
    Views:
    199
    are Dogue
    May 18, 2011
Loading...

Share This Page