How to read all files present in a directory in C ?

Discussion in 'C Programming' started by vsk, Jan 18, 2005.

  1. vsk

    vsk Guest

    Hai All,
    How to read all files present in a directory in C ?.
    Thanks,
    vsk, Jan 18, 2005
    #1
    1. Advertising

  2. vsk

    Ben Pfaff Guest

    "vsk" <> writes:

    > How to read all files present in a directory in C ?.


    This is in the FAQ.

    19.20: How can I read a directory in a C program?

    A: See if you can use the opendir() and readdir() functions, which
    are part of the POSIX standard and are available on most Unix
    variants. Implementations also exist for MS-DOS, VMS, and other
    systems. (MS-DOS also has FINDFIRST and FINDNEXT routines which
    do essentially the same thing.) readdir() only returns file
    names; if you need more information about the file, try calling
    stat(). To match filenames to some wildcard pattern, see
    question 13.7.

    References: K&R2 Sec. 8.6 pp. 179-184; PCS Sec. 13 pp. 230-1;
    POSIX Sec. 5.1; Schumacher, ed., _Software Solutions in C_
    Sec. 8.
    --
    "When in doubt, treat ``feature'' as a pejorative.
    (Think of a hundred-bladed Swiss army knife.)"
    --Kernighan and Plauger, _Software Tools_
    Ben Pfaff, Jan 18, 2005
    #2
    1. Advertising

  3. Ben Pfaff wrote:
    > "vsk" <> writes:
    >
    >
    >> How to read all files present in a directory in C ?.

    >
    >
    > This is in the FAQ.
    >
    > 19.20: How can I read a directory in a C program?
    >
    > A: See if you can use the opendir() and readdir() functions, which
    > are part of the POSIX standard and are available on most Unix
    > variants. Implementations also exist for MS-DOS, VMS, and other
    > systems. (MS-DOS also has FINDFIRST and FINDNEXT routines which
    > do essentially the same thing.) readdir() only returns file
    > names; if you need more information about the file, try calling
    > stat(). To match filenames to some wildcard pattern, see
    > question 13.7.
    >
    > References: K&R2 Sec. 8.6 pp. 179-184; PCS Sec. 13 pp. 230-1;
    > POSIX Sec. 5.1; Schumacher, ed., _Software Solutions in C_
    > Sec. 8.


    Ben, a suggestion: also include the link to the
    FAQ. Your reply doesn't inform the OP how to get
    to the FAQ or where it came from. Hmmmm, kind of
    like citing your references. ;-)


    --
    Thomas Matthews

    C++ newsgroup welcome message:
    http://www.slack.net/~shiva/welcome.txt
    C++ Faq: http://www.parashift.com/c -faq-lite
    C Faq: http://www.eskimo.com/~scs/c-faq/top.html
    alt.comp.lang.learn.c-c++ faq:
    http://www.comeaucomputing.com/learn/faq/
    Other sites:
    http://www.josuttis.com -- C++ STL Library book
    http://www.sgi.com/tech/stl -- Standard Template Library
    Thomas Matthews, Jan 18, 2005
    #3
  4. vsk

    Mike Wahler Guest

    "Thomas Matthews" <> wrote in
    message news:...
    > Ben, a suggestion: also include the link to the
    > FAQ. Your reply doesn't inform the OP how to get
    > to the FAQ or where it came from. Hmmmm, kind of
    > like citing your references. ;-)


    I'm all for helping folks, but imo the 'hand holding'
    can get out of hand, causing some to view the regulars
    here as virtual servants. Anyone can type "C FAQ" into
    google and find it. Ben did give the FAQ item number
    with his quotation.

    [insert that stuff about fish and feeding folks]


    -Mike
    Mike Wahler, Jan 18, 2005
    #4
  5. vsk

    Newcomer Guest

    In article <noeHd.1400$>, Mike
    Wahler <> wrote:

    > "Thomas Matthews" <> wrote in
    > message news:...
    > > Ben, a suggestion: also include the link to the
    > > FAQ. Your reply doesn't inform the OP how to get
    > > to the FAQ or where it came from. Hmmmm, kind of
    > > like citing your references. ;-)

    >
    > I'm all for helping folks, but imo the 'hand holding'
    > can get out of hand, causing some to view the regulars
    > here as virtual servants. Anyone can type "C FAQ" into
    > google and find it.


    Such behaviour also helps keep the 'elect' and the mere rabble
    separate. What's more important? To help those who need it, or to show
    disdain for those who don't know what you happen to know?

    FAQ's are very often concerned with netiquette and topical definitions;
    and I for one had not assumed there was a collection of 'those' sort of
    frequent questions about C.

    However if this (suggested by Google)

    http://www.eskimo.com/~scs/C-faq/faq.html

    was what you were talking about, it wouldn't open.

    neither would this (suggested by Google)

    http://www.eskimo.com/~scs/C-faq/questions.htmll

    nor this (suggested by Google)

    http://www.lysator.liu.se/c/c-faq/

    However, I did have better luck with this:

    http://www.cdc.gov/ncidod/diseases/hepatitis/c/faq.htm

    Is this what you meant? I'm tempted to add 'FAQED'.


    Another Newcomer
    Newcomer, Jan 19, 2005
    #5
  6. vsk

    pete Guest

    Newcomer wrote:
    >
    > In article <noeHd.1400$>, Mike
    > Wahler <> wrote:
    >
    > > "Thomas Matthews" <> wrote in
    > > message news:...
    > > > Ben, a suggestion: also include the link to the
    > > > FAQ. Your reply doesn't inform the OP how to get
    > > > to the FAQ or where it came from. Hmmmm, kind of
    > > > like citing your references. ;-)

    > >
    > > I'm all for helping folks, but imo the 'hand holding'
    > > can get out of hand, causing some to view the regulars
    > > here as virtual servants. Anyone can type "C FAQ" into
    > > google and find it.

    >
    > Such behaviour also helps keep the 'elect' and the mere rabble
    > separate. What's more important? To help those who need it, or to show
    > disdain for those who don't know what you happen to know?
    >
    > FAQ's are very often concerned with netiquette and topical definitions;
    > and I for one had not assumed there was a collection of 'those' sort of
    > frequent questions about C.
    >
    > However if this (suggested by Google)
    >
    > http://www.eskimo.com/~scs/C-faq/faq.html
    >
    > was what you were talking about, it wouldn't open.


    I think the server's down.
    Try again later.

    --
    pete
    pete, Jan 19, 2005
    #6
    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. TJS
    Replies:
    1
    Views:
    499
    Eliyahu Goldin
    Jun 23, 2004
  2. Replies:
    1
    Views:
    570
    Evertjan.
    Sep 30, 2005
  3. Ralf Wahner
    Replies:
    5
    Views:
    619
    Bob Foster
    Dec 24, 2003
  4. pradeep
    Replies:
    5
    Views:
    343
    Vladimir Lushnikov
    Apr 27, 2006
  5. Replies:
    1
    Views:
    166
    Evertjan.
    Sep 30, 2005
Loading...

Share This Page