Equivalent of ls -d

Discussion in 'Perl Misc' started by Another Brian, Mar 24, 2006.

  1. I'm trying to get a list of the files and directories. I was using:
    my @FILES = `ls -ld $INPUT`;

    Where the value being passed into $INPUT includes a wild card that
    identifies lots of files and directories. I am getting this error:
    ksh: /acct/v/vobadm/bin/stattest.pl: 0403-027 The parameter list is
    too long.

    I do not want to descend into subdirectories. I tried using readdir
    but if $INPUT contains a wild card, it lists the files in the
    subdirectories.

    Is there a Perl equivalent of "ls -d $INPUT"?

    Thank you,
    Brian
     
    Another Brian, Mar 24, 2006
    #1
    1. Advertising

  2. "Another Brian" <> wrote in
    news::

    > I'm trying to get a list of the files and directories. I was using:
    > my @FILES = `ls -ld $INPUT`;
    >
    > Where the value being passed into $INPUT includes a wild card that
    > identifies lots of files and directories. I am getting this error:
    > ksh: /acct/v/vobadm/bin/stattest.pl: 0403-027 The parameter list is
    > too long.
    >
    > I do not want to descend into subdirectories. I tried using readdir
    > but if $INPUT contains a wild card, it lists the files in the
    > subdirectories.


    Huh?

    Could you please share with us the code that does that?

    Sinan

    --
    A. Sinan Unur <>
    (remove .invalid and reverse each component for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
     
    A. Sinan Unur, Mar 24, 2006
    #2
    1. Advertising

  3. Another Brian

    Guest

    "Another Brian" <> wrote:
    > I'm trying to get a list of the files and directories. I was using:
    > my @FILES = `ls -ld $INPUT`;
    >
    > Where the value being passed into $INPUT includes a wild card that
    > identifies lots of files and directories. I am getting this error:
    > ksh: /acct/v/vobadm/bin/stattest.pl: 0403-027 The parameter list is
    > too long.


    Yep, that is a shell limitation.

    > I do not want to descend into subdirectories. I tried using readdir
    > but if $INPUT contains a wild card, it lists the files in the
    > subdirectories.


    I find that hard to believe. Can you demonstrate this?

    >
    > Is there a Perl equivalent of "ls -d $INPUT"?


    On a modern perl, its standard glob can deal with much larger file lists
    than the shell can. It naturally does the equivalent ls's -d. To simulate
    ls's -l you would need to stat each file coming out of glob.

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
     
    , Mar 24, 2006
    #3
  4. Another Brian

    Juha Laiho Guest

    "Another Brian" <> said:
    >I'm trying to get a list of the files and directories. I was using:
    >my @FILES = `ls -ld $INPUT`;

    ....
    >I do not want to descend into subdirectories. I tried using readdir
    >but if $INPUT contains a wild card, it lists the files in the
    >subdirectories.


    You can check the entries returned from readdir -- see
    perldoc -f -X

    .... f.ex.

    $ent = readdir( DIR );
    if (-f $ent) {
    // do something for plain files
    }

    --
    Wolf a.k.a. Juha Laiho Espoo, Finland
    (GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
    PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
    "...cancel my subscription to the resurrection!" (Jim Morrison)
     
    Juha Laiho, Mar 24, 2006
    #4
  5. <> wrote in message
    news:20060324122449.376$...
    > "Another Brian" <> wrote:
    >> I'm trying to get a list of the files and directories. I was using:
    >> my @FILES = `ls -ld $INPUT`;
    >>
    >> Where the value being passed into $INPUT includes a wild card that
    >> identifies lots of files and directories. I am getting this error:
    >> ksh: /acct/v/vobadm/bin/stattest.pl: 0403-027 The parameter list is
    >> too long.

    >
    > Yep, that is a shell limitation.
    >
    >> I do not want to descend into subdirectories. I tried using readdir
    >> but if $INPUT contains a wild card, it lists the files in the
    >> subdirectories.

    >
    > I find that hard to believe. Can you demonstrate this?
    >

    Unfortunately I've deleted the test code and haven't been able to
    quickly recreate it.
    >>
    >> Is there a Perl equivalent of "ls -d $INPUT"?

    >
    > On a modern perl, its standard glob can deal with much larger file
    > lists
    > than the shell can. It naturally does the equivalent ls's -d. To
    > simulate
    > ls's -l you would need to stat each file coming out of glob.
    >

    GLOB! That's the command. I was just too brain dead to remember it.
    Thank you. It works great!

    Brian.
     
    Another Brian, Mar 24, 2006
    #5
    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. Brendan Duffy

    Re: Image Scanning - TWAIN equivalent

    Brendan Duffy, Jul 24, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    1,486
    Brendan Duffy
    Jul 24, 2003
  2. Lolo
    Replies:
    3
    Views:
    595
  3. Sanjeev
    Replies:
    4
    Views:
    3,573
    Jonathan Bromley
    Jul 23, 2004
  4. Eric Peers
    Replies:
    2
    Views:
    1,369
    Jonathan Bromley
    Nov 18, 2004
  5. mag
    Replies:
    1
    Views:
    665
    Andy Peters
    May 19, 2005
Loading...

Share This Page