473,396 Members | 1,765 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 3647
-----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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: David Jacques | last post by:
I am trying to get a list of all files of a certain extension type on disk to do some processing in a loop. The code needs to be portable to UNIX, so I need to use plain c functionality. Does...
9
by: minil | last post by:
Hi any c function in linux to return size of directory (Including its files & subdirectories & its files).. I can stat() only files . not for directories. please reply me soon Thanks in...
2
by: Martin | last post by:
Hi, I have implemeted a recursive function that basically iterate throught the entire file system and prints out the entire path of each directory that it come across. The only problem is the...
11
by: F. Michael Miller | last post by:
I'd like to copy the listing of a directory (& sub directories) to a text file in vb.net. I'm looking for teh equivilant of the DOS command dir /s > TargetFile.txt. Thanks!
22
by: rtilley | last post by:
# Spaces are present before and after the XXX filename = ' XXX ' new_filename = filename.strip() if new_filename != filename: print filename Macs allow these spaces in file and folder...
3
by: Daniel C. Di Vita | last post by:
I am stating to write a small app that allows a user to catalog their CD/dvd collection. I need some help, however. Here is some test code I wrote for the recursive listing: Imports System...
7
by: Kristan | last post by:
Hi there, quick question, how would I retrieve a list of files in ANSI C in a purely platform independent way? Any pointers would be great! thanks Kristan
5
by: johnwayne83 | last post by:
This is my first semester in c++ and i took java last semester. I need some help and i really cant find any information that has helped me or to point me in the right direction. I am using...
8
by: aki | last post by:
Hi All, I describe the problem as below. A directory( path known) , contains 0 to any number of files . The file names are with following structure : ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.