Re: Directory reading

Discussion in 'C Programming' started by thomas.mertes@gmx.at, Dec 5, 2008.

  1. Guest

    On 4 Dez., 21:19, mattia <> wrote:
    > Hi everyone, can you suggest me an efficient way to list all the files in
    > a directory (under linux)?


    As proposed by others, the functions opendir(), readdir()
    and closedir() are the way to read a directory under
    Linux/UNIX/Bsd.

    Even under some Windows compilers like MINGW support
    for opendir(), readdir() and closedir() can be found.
    I know you asked for Linux, but I think that portability
    is always important.

    If a C compiler/library does not support the functions
    opendir(), readdir() and closedir() there is another
    solution. It is easy to write implementations of this
    functions based on findfirst() and findnext() under DOS
    or FindFirstFileA and FindNextFileA under Windows.

    I implemented this functions and (wide character
    versions of them). This functions are available
    (licensed with the LGPL) as part of the Seed7 package
    (see: seed7/src/dir_win.c).

    Unicode characters bring up a different problem. Modern
    versions of Linux use UTF-8 and the directory read
    functions deliver also UTF-8.

    Under windows wide characters are used instead of
    UTF-8. As mentioned above I wrote also implementations
    of wopendir(), wreaddir() and wclosedir() which are
    based on FindFirstFileW and FindNextFileW under Windows.

    Since there are UTF-8 and UTF-16 (wide character)
    functions, there needs to be something which balances
    this differences. For this purpose I defined the functions
    dirOpen, dirRead and dirClose which can be found in
    the file seed7/src/dir_rtl.c (in the Seed7 package).

    I hope that helps.

    Greetings Thomas Mertes

    Seed7 Homepage: http://seed7.sourceforge.net
    Seed7 - The extensible programming language: User defined statements
    and operators, abstract data types, templates without special
    syntax, OO with interfaces and multiple dispatch, statically typed,
    interpreted or compiled, portable, runs under linux/unix/windows.
    , Dec 5, 2008
    #1
    1. Advertising

  2. CBFalconer Guest

    wrote:
    > mattia <> wrote:
    >
    >> Hi everyone, can you suggest me an efficient way to list all the
    >> files in a directory (under linux)?

    >
    > As proposed by others, the functions opendir(), readdir() and
    > closedir() are the way to read a directory under Linux/UNIX/Bsd.


    As pointed out elsewhere, these functions are NOT part of standard
    ISO C, and thus are off-topic on c.l.c. A reference to a suitable
    newsgroup is much better than this off-topic answer. Try
    comp.unix.programmer.

    --
    [mail]: Chuck F (cbfalconer at maineline dot net)
    [page]: <http://cbfalconer.home.att.net>
    Try the download section.
    CBFalconer, Dec 5, 2008
    #2
    1. Advertising

  3. Ian Collins Guest

    CBFalconer wrote:
    > wrote:
    >> mattia <> wrote:
    >>
    >>> Hi everyone, can you suggest me an efficient way to list all the
    >>> files in a directory (under linux)?

    >> As proposed by others, the functions opendir(), readdir() and
    >> closedir() are the way to read a directory under Linux/UNIX/Bsd.

    >
    > As pointed out elsewhere, these functions are NOT part of standard
    > ISO C, and thus are off-topic on c.l.c. A reference to a suitable
    > newsgroup is much better than this off-topic answer. Try
    > comp.unix.programmer.
    >

    Is there an echo in here?

    --
    Ian Collins
    Ian Collins, Dec 5, 2008
    #3
  4. Guest

    On 6 Dez., 00:04, CBFalconer <> wrote:
    > wrote:
    > > mattia <> wrote:

    >
    > >> Hi everyone, can you suggest me an efficient way to list all the
    > >> files in a directory (under linux)?

    >
    > > As proposed by others, the functions opendir(), readdir() and
    > > closedir() are the way to read a directory under Linux/UNIX/Bsd.

    >
    > As pointed out elsewhere, these functions are NOT part of standard
    > ISO C, and thus are off-topic on c.l.c. A reference to a suitable
    > newsgroup is much better than this off-topic answer. Try
    > comp.unix.programmer.


    IMHO c.l.c is about C (which includes also some C code which is
    portable with reasonable effort).

    Nevertheless:
    Instead of telling somebody "Go to comp.unix.programmer", waiting
    until he shows up there, going there myself, answering his question,
    telling him that I have also a solution for Windows which I will
    answer in "comp.os.ms-windows.programmer.win32", waiting for
    him to show up there, telling about my Windows solution, telling
    him that the wide char solution for unicode characters cannot be
    used under linux but that I will tell him about that at
    "comp.os.linux.development.apps", waiting for him to show up there,
    telling about UTF-8, telling that I have a solution which works
    under Linux/Unix/Bsd and Windows with ascii and unicode characters
    about which I can only tell at "comp.lang.misc", wait until he shows
    up there, tell about my portable interface functions which are
    are part of the Seed7 package and are licensed under the LGPL,
    I decided to provide the information directly.

    This saves time for me and the OP, unless someone asks why I did
    write a little howto about directorys at one place instead of
    several places where everybody else would have problems to follow.

    In this case it is necessary to explain how complicated things
    become, when half of the time is used to discuss, if something is
    off or on topic.

    At least I did not tell that I was able to transfer those funds,
    that you won in a mail lottery, that I am a bank officer who just
    found a big account whos owner died in an aircrash, that you can
    get cheap loans, that you can work as company payment representative
    who receives big commissions for doing money transfers, that you
    can buy someting to enlarge your genitals, an offer to buy cheap
    drugs or some other bullshit (did I miss something?).

    BTW: You will get rich and get all sexual partners you desire
    when you are using Seed7 (for me it works). If you don't use it
    (and tell at least 10 friends) misfortune may probably come ...

    Greetings Thomas Mertes

    Seed7 Homepage: http://seed7.sourceforge.net
    Seed7 - The extensible programming language: User defined statements
    and operators, abstract data types, templates without special
    syntax, OO with interfaces and multiple dispatch, statically typed,
    interpreted or compiled, portable, runs under linux/unix/windows.
    , Dec 6, 2008
    #4
  5. On Dec 6, 1:20 pm, wrote:
    > On 6 Dez., 00:04, CBFalconer <> wrote:
    >
    > > wrote:
    > > > mattia <> wrote:

    >
    > > >> Hi everyone, can you suggest me an efficient way to list all the
    > > >> files in a directory (under linux)?

    >
    > > > As proposed by others, the functions opendir(), readdir() and
    > > > closedir() are the way to read a directory under Linux/UNIX/Bsd.

    >
    > > As pointed out elsewhere, these functions are NOT part of standard
    > > ISO C, and thus are off-topic on c.l.c.  A reference to a suitable
    > > newsgroup is much better than this off-topic answer.  Try
    > > comp.unix.programmer.

    >
    > IMHO c.l.c is about C (which includes also some C code which is
    > portable with reasonable effort).
    >
    > Nevertheless:
    > Instead of telling somebody "Go to comp.unix.programmer", waiting
    > until he shows up there, going there myself, answering his question,
    > telling him that I have also a solution for Windows which I will
    > answer in "comp.os.ms-windows.programmer.win32", waiting for
    > him to show up there, telling about my Windows solution, telling
    > him that the wide char solution for unicode characters cannot be
    > used under linux but that I will tell him about that at
    > "comp.os.linux.development.apps", waiting for him to show up there,
    > telling about UTF-8, telling that I have a solution which works
    > under Linux/Unix/Bsd and Windows with ascii and unicode characters
    > about which I can only tell at "comp.lang.misc", wait until he shows
    > up there, tell about my portable interface functions which are
    > are part of the Seed7 package and are licensed under the LGPL,
    > I decided to provide the information directly.
    >
    > This saves time for me and the OP, unless someone asks why I did
    > write a little howto about directorys at one place instead of
    > several places where everybody else would have problems to follow.
    >
    > In this case it is necessary to explain how complicated things
    > become, when half of the time is used to discuss, if something is
    > off or on topic.
    >
    > At least I did not tell that I was able to transfer those funds,
    > that you won in a mail lottery, that I am a bank officer who just
    > found a big account whos owner died in an aircrash, that you can
    > get cheap loans, that you can work as company payment representative
    > who receives big commissions for doing money transfers, that you
    > can buy someting to enlarge your genitals, an offer to buy cheap
    > drugs or some other bullshit (did I miss something?).
    >
    > BTW: You will get rich and get all sexual partners you desire
    > when you are using Seed7 (for me it works). If you don't use it
    > (and tell at least 10 friends) misfortune may probably come ...
    >
    > Greetings Thomas Mertes
    >
    > Seed7 Homepage:  http://seed7.sourceforge.net
    > Seed7 - The extensible programming language: User defined statements
    > and operators, abstract data types, templates without special
    > syntax, OO with interfaces and multiple dispatch, statically typed,
    > interpreted or compiled, portable, runs under linux/unix/windows.


    Thumbs up.
    Sri Harsha Dandibhotla, Dec 15, 2008
    #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. TJS
    Replies:
    1
    Views:
    507
    Eliyahu Goldin
    Jun 23, 2004
  2. Jack Wright
    Replies:
    1
    Views:
    462
    sonikchopra
    Apr 19, 2005
  3. =?Utf-8?B?QmFzIEhlbmRyaWtz?=

    Directory and files names in temporary asp.net directory

    =?Utf-8?B?QmFzIEhlbmRyaWtz?=, Jan 28, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    824
    Juan T. Llibre
    Jan 31, 2005
  4. Steve Singer
    Replies:
    0
    Views:
    531
    Steve Singer
    Feb 15, 2005
  5. davidw
    Replies:
    2
    Views:
    543
    Brock Allen
    May 30, 2005
Loading...

Share This Page