468,103 Members | 1,332 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,103 developers. It's quick & easy.

Directory/File recursive listing using standard/portable C?

Just curious: is it possible to recursively list all the
directorys/files inside a given directory using standard c i/o library
routines only, which can be re-compiled and run on any os supportes c
compiler? Or this is too os dependent, system-specific functions must
be called?
I think about this when i tried to do this under windows, i found in
order to achieve this, some windows-specific api such as
FindFirstFile, FindNextFile must be used, so anyway not using them?

Forgive my poor English, Thanks in advance.
Nov 14 '05 #1
10 3435
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

ibic wrote:
Just curious: is it possible to recursively list all the
directorys/files inside a given directory using standard c i/o library
routines only,


Sorry, but standard C does not recognize the concept of a directory, and there
are no functions in the standard C library to list (recursively or otherwise)
the contents of directories.

You are going to have to look to an extension that supports such things. FWIW,
the POSIX extensions to C are useable under a large number of operating systems,
including all Unix-ish systems, and (so I am told) Microsoft Windows.

- --
Lew Pitcher
IT Consultant, Enterprise Data Systems,
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed are my own, not my employers')
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)

iD8DBQFBmRJeagVFX4UWr64RApeWAKClqSiabUpuryinHORf3L rz7DpUFQCdEPGd
E4jOFEQUvljD0ASNp5sndG8=
=MPTi
-----END PGP SIGNATURE-----
Nov 14 '05 #2
On 15 Nov 2004 12:19:52 -0800, ib****@gmail.com (ibic) wrote:
Just curious: is it possible to recursively list all the
directorys/files inside a given directory using standard c i/o library
routines only, which can be re-compiled and run on any os supportes c
compiler? Or this is too os dependent, system-specific functions must
be called?
I think about this when i tried to do this under windows, i found in
order to achieve this, some windows-specific api such as
FindFirstFile, FindNextFile must be used, so anyway not using them?


And you should be aware that there are major operating systems which
don't use directories at all.
<<Remove the del for email>>
Nov 14 '05 #3
In <fn********************************@4ax.com> Barry Schwarz <sc******@deloz.net> writes:
And you should be aware that there are major operating systems which
don't use directories at all.


Calling them "major" is a bit of an exaggeration, these days. "Legacy"
is a more appropriate term.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Currently looking for a job in the European Union
Nov 14 '05 #4
rOn 16 Nov 2004 14:29:32 GMT, Da*****@cern.ch (Dan Pop) wrote:
In <fn********************************@4ax.com> Barry Schwarz <sc******@deloz.net> writes:
And you should be aware that there are major operating systems which
don't use directories at all.


Calling them "major" is a bit of an exaggeration, these days. "Legacy"
is a more appropriate term.


*I* have a hard time calling something whose newest release is less
than a year old "legacy". *B*ut I don't have a hard time calling
something that generates hundreds of millions of dollars of revenue
for its vendor "major". *M*aybe we just look at things differently.
<<Remove the del for email>>
Nov 14 '05 #5
"Barry Schwarz" <sc******@deloz.net> wrote in message
news:pl********************************@4ax.com...
rOn 16 Nov 2004 14:29:32 GMT, Da*****@cern.ch (Dan Pop) wrote:
In <fn********************************@4ax.com> Barry Schwarz <sc******@deloz.net> writes:
And you should be aware that there are major operating systems which
don't use directories at all.


Calling them "major" is a bit of an exaggeration, these days. "Legacy"
is a more appropriate term.


*I* have a hard time calling something whose newest release is less
than a year old "legacy". *B*ut I don't have a hard time calling
something that generates hundreds of millions of dollars of revenue
for its vendor "major". *M*aybe we just look at things differently.


Please Master, break the news upon us...
Let us in on this major secret...
Deliver us from evil directory trees !
Let the world be flat again !

Chqrlie
Nov 14 '05 #6
In <pl********************************@4ax.com> Barry Schwarz <sc******@deloz.net> writes:
rOn 16 Nov 2004 14:29:32 GMT, Da*****@cern.ch (Dan Pop) wrote:
In <fn********************************@4ax.com> Barry Schwarz <sc******@deloz.net> writes:
And you should be aware that there are major operating systems which
don't use directories at all.


Calling them "major" is a bit of an exaggeration, these days. "Legacy"
is a more appropriate term.


*I* have a hard time calling something whose newest release is less
than a year old "legacy". *B*ut I don't have a hard time calling
something that generates hundreds of millions of dollars of revenue
for its vendor "major". *M*aybe we just look at things differently.


It might be a major product for its vendor, it's still a legacy OS for
those stuck with it. At a previous job, one of the main reasons they
decided to get rid of their large mainframe configuration was precisely
the lack of directory support.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Currently looking for a job in the European Union
Nov 14 '05 #7

In article <cn**********@sunnews.cern.ch>, Da*****@cern.ch (Dan Pop) writes:

It might be a major product for its vendor, it's still a legacy OS for
those stuck with it.
Mainframes are selling like (expensive) hotcakes, and plenty of their
users are still very happy with them. As a definition of "legacy",
this is pretty useless.
At a previous job, one of the main reasons they
decided to get rid of their large mainframe configuration was precisely
the lack of directory support.


We can play dueling anecdotes all day.

Call them "legacy" if you like, but I'm with Barry on this one. In
any event, there are people writing C programs that have to run on
platforms where there is no hierarchical directory structure such as
the OP's project assumed. Obviously, there are also many C programs
being written that make that assumption and get along fine, since
they never need to run on such a platform.

--
Michael Wojcik mi************@microfocus.com

I said, 'I need to put my soul into my work and it is well known that
computers haven't got a soul.' My father said, 'The Americans are working
on it.' -- Sue Townsend, _The Secret Diary of Adrian Mole, Aged 13 3/4_
Nov 14 '05 #8

In article <cn**********@reader1.imaginet.fr>, "Charlie Gordon" <ne**@chqrlie.org> writes:
"Barry Schwarz" <sc******@deloz.net> wrote in message
news:pl********************************@4ax.com...
rOn 16 Nov 2004 14:29:32 GMT, Da*****@cern.ch (Dan Pop) wrote:
In <fn********************************@4ax.com> Barry Schwarz <sc******@deloz.net> writes:
>And you should be aware that there are major operating systems which
>don't use directories at all.

Calling them "major" is a bit of an exaggeration, these days. "Legacy"
is a more appropriate term.
*I* have a hard time calling something whose newest release is less
than a year old "legacy". *B*ut I don't have a hard time calling
something that generates hundreds of millions of dollars of revenue
for its vendor "major". *M*aybe we just look at things differently.


Please Master, break the news upon us...
Let us in on this major secret...


It's hardly a secret. A little research would suffice to identify
operating systems that do not use hierarchical-directory filesystems
(at least for their dominant filesystem), or use something which may
resemble a hierarchical-directory filesystem in some respects but not
in others (so that the OP's project would not be applicable). OS/400
is one; zOS is another.
Let the world be flat again !


Such research would also demonstrate that filesystems without
hierarchical directories (in the Unix model) need not be flat.

--
Michael Wojcik mi************@microfocus.com

Most people believe that anything that is true is true for a reason.
These theorems show that some things are true for no reason at all,
i.e., accidentally, or at random. -- G J Chaitin
Nov 14 '05 #9
In <cn********@news3.newsguy.com> mw*****@newsguy.com (Michael Wojcik) writes:

In article <cn**********@sunnews.cern.ch>, Da*****@cern.ch (Dan Pop) writes:

It might be a major product for its vendor, it's still a legacy OS for
those stuck with it.
Mainframes are selling like (expensive) hotcakes, and plenty of their

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Any factual evidence for that? From my own experience, their market is
getting narrower and narrower. I've witnessed the phasing out of
mainframes at two sites, but I've never seen a site adopting them as the
right solution for its problems. I've a strong feeling that the new
mainframes sold replace old mainframes rather than increasing the number
of mainframes in current use. Hence the "legacy" thing.
users are still very happy with them.
The users are happy that their legacy applications continue to work.
Few people develop *new* applications for that platform.
As a definition of "legacy", this is pretty useless.


I don't think so. Compare the number of mainframe installations today
with that of 20 - 25 years ago. Ditto about the amount of new software
developed for mainframes. And, finally, try to figure out the health
state of BITNET/EARN today.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Currently looking for a job in the European Union
Nov 14 '05 #10
On 17 Nov 2004 19:43:04 GMT, mw*****@newsguy.com (Michael Wojcik)
wrote:
>>And you should be aware that there are major operating systems which
>>don't use directories at all.
<snip> It's hardly a secret. A little research would suffice to identify
operating systems that do not use hierarchical-directory filesystems
(at least for their dominant filesystem), or use something which may
resemble a hierarchical-directory filesystem in some respects but not
in others (so that the OP's project would not be applicable). OS/400
is one; zOS is another.
Let the world be flat again !


Such research would also demonstrate that filesystems without
hierarchical directories (in the Unix model) need not be flat.


And to avoid being forgotten, the Guardian personality/mode of
Tandem^WCompaq^WHP NonStop, which is still used and needed for some
new applications because it provides features the POSIX personality
cannot although the overwhelming majority of applications are legacy,
has exactly two levels of directory per disk (or pseudodisk) -- or
actually, two levels of naming in a global directory rather like the
OS/360-et-seq system catalog. Thus you can enumerate files in a
directory -- with a native API, actually two(!) of them, different
from either the Windows or POSIX ones -- and disks (and other devices)
and systems with (sometimes) different API(s) -- but you can never
find or enumerate a (sub)directory in a directory. Of course, if your
code just goes by what you get from the enumeration it is only a waste
of effort but no real harm to handle an impossible case.

- David.Thompson1 at worldnet.att.net
Nov 14 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by David Jacques | last post: by
9 posts views Thread by minil | last post: by
2 posts views Thread by Martin | last post: by
11 posts views Thread by F. Michael Miller | last post: by
3 posts views Thread by Daniel C. Di Vita | last post: by
7 posts views Thread by Kristan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.