Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: Directory reading

Reply
Thread Tools

Re: Directory reading

 
 
thomas.mertes@gmx.at
Guest
Posts: n/a
 
      12-05-2008
On 4 Dez., 21:19, mattia <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
 
CBFalconer
Guest
Posts: n/a
 
      12-05-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> mattia <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      12-05-2008
CBFalconer wrote:
> (E-Mail Removed) wrote:
>> mattia <(E-Mail Removed)> 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
 
Reply With Quote
 
thomas.mertes@gmx.at
Guest
Posts: n/a
 
      12-06-2008
On 6 Dez., 00:04, CBFalconer <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:
> > mattia <(E-Mail Removed)> 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.
 
Reply With Quote
 
Sri Harsha Dandibhotla
Guest
Posts: n/a
 
      12-15-2008
On Dec 6, 1:20*pm, (E-Mail Removed) wrote:
> On 6 Dez., 00:04, CBFalconer <(E-Mail Removed)> wrote:
>
> > (E-Mail Removed) wrote:
> > > mattia <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
System.IO.Directory.GetDirectories() and System.IO.Directory.GetFiles() are not returning the specified directory Nathan Sokalski ASP .Net 2 09-06-2007 03:58 PM
UnauthorizedAccessException when reading XML files (no problem when reading other file-types) blabla120@gmx.net ASP .Net 0 09-15-2006 02:08 PM
DVD ROM not reading DVDs but reading CDs sayeed.afzal@gmail.com Computer Information 0 05-22-2006 10:37 AM
ASP.NET Reading problem (reading .xls) Wael Soliman ASP .Net 2 01-03-2005 05:33 PM
reading the DB vs. reading a text file...performance preference? Darrel ASP .Net 3 11-11-2004 02:27 PM



Advertisments