Google
 
Webnews.only-4-geeks.com
Interesting places
news.only-4-geeks.com Forum Index » CGoto page 1, 2  Next

directories

 
Jump to:  
 
sid
PostPosted: Fri Jun 27, 2008 8:51 am    Post subject: directories
       
Hi
I want to write a C program that can read directories (say list them
as well).
I found out that we could use an API provided by dirent.h header file,
but I am not too keen on using the API. I want to access it directly
without any API. Any help is welcome.
Thank you.
 

 
Jens Thoms Toerring
PostPosted: Fri Jun 27, 2008 8:51 am    Post subject: Re: directories
       
sid <kingsiddharth@gmail.com> wrote:
Quote:
I want to write a C program that can read directories (say list them
as well).
I found out that we could use an API provided by dirent.h header file,
but I am not too keen on using the API. I want to access it directly
without any API. Any help is welcome.

Since C programs also have to run on machines were directories
don't exist there are no functions in standard C for e.g. lis-
ting the contents of a directory. Instead you have to use some
functions that are supplied by your system. On e. g. POSIX com-
pliant systems these are opendir(), readdir() and closedir().
On others you may have to use other functions.

I don't know what you mean with "I want to access it directly
without any API." Do you want to extract the directory infor-
mation directly from the raw data on the disk? That would be
a rather difficult task and would make your program extremely
system specific (and would work only for the types of file
systems you include support for in your program). If you are
looking for information about this you have to ask in a group
that deals with low level programming on your target system.

Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ LINK
 

 
Erik Trulsson
PostPosted: Fri Jun 27, 2008 8:51 am    Post subject: Re: directories
       
sid <kingsiddharth@gmail.com> wrote:
Quote:
Hi
I want to write a C program that can read directories (say list them
as well).
I found out that we could use an API provided by dirent.h header file,
but I am not too keen on using the API. I want to access it directly
without any API. Any help is welcome.
Thank you.

Standard C does not provide any support for reading or otherwise handling
directories.

You will have to use some platform-specific extensions to accomplish that.
Under Unix (with relatives) you can use opendir()/readdir().
Other systems may require other solutions.





--
<Insert your favourite quote here.>
Erik Trulsson
ertr1013@student.uu.se
 

 
Bob Nelson
PostPosted: Fri Jun 27, 2008 8:51 am    Post subject: Re: directories
       
sid wrote:

Quote:
I want to write a C program that can read directories (say list them
as well).

Functions for ``directory'' operations do not exist in C.

Although that's a terse response, I think the above is completely accurate
within the context of c.l.c. In spite of its presumptive accuracy, it's
certainly not prescriptive nor helpful to the poster. A C translator that
offers only ``wrong!'' as a diagnostic has fulfilled the letter of the
standard but is a questionable implementation.

Therefore seek counsel concerning the reading of directories elsewhere.

There are resources in book form by reputable authors as well as other
newsgroups appropriate for your environment. And as K&R so aptly phrase it,
you may also ``...check with a local expert''. The reading and manipulation
of directories will go beyond the scope of C.
 

 
Chris Dollin
PostPosted: Fri Jun 27, 2008 9:33 am    Post subject: Re: directories
       
sid wrote:

Quote:
Hi
I want to write a C program that can read directories (say list them
as well).
I found out that we could use an API provided by dirent.h header file,
but I am not too keen on using the API. I want to access it directly
without any API.

This is called "asking for trouble". Avoiding an API for doing X
can be like avoiding safety goggles, ignoring RADIATION signs,
or connecting your computer to the mains by stuffing the wires
into the socket holes directly without the inconvenience of a plug.

Sometimes you need to get behind the API. More often, you only /think/
you need to.

--
"Its deductive method was holistic, totalising, /Perdido Street Station/
and inconstant."

Hewlett-Packard Limited registered no:
registered office: Cain Road, Bracknell, Berks RG12 1HN 690597 England
 

 
Richard Tobin
PostPosted: Fri Jun 27, 2008 10:17 am    Post subject: Re: directories
       
In article <e375c1f0-a8db-4b63-b819-cef24f27af5a@79g2000hsk.googlegroups.com>,
sid <kingsiddharth@gmail.com> wrote:

Quote:
I found out that we could use an API provided by dirent.h header file,
but I am not too keen on using the API. I want to access it directly
without any API. Any help is welcome.

There may not be any way to do so. The operating system may not
provide a method of reading the directory directly. If it does, it
may only do so for certain filesystem types.

Why do you want to do this? What is the real problem you are trying to
solve?

-- Richard

--
In the selection of the two characters immediately succeeding the numeral 9,
consideration shall be given to their replacement by the graphics 10 and 11 to
facilitate the adoption of the code in the sterling monetary area. (X3.4-1963)
 

 
Ben Bacarisse
PostPosted: Fri Jun 27, 2008 12:03 pm    Post subject: Re: directories
       
jt@toerring.de (Jens Thoms Toerring) writes:

Quote:
sid <kingsiddharth@gmail.com> wrote:
I want to write a C program that can read directories (say list them
as well).
I found out that we could use an API provided by dirent.h header file,
but I am not too keen on using the API. I want to access it directly
without any API. Any help is welcome.

Since C programs also have to run on machines were directories
don't exist there are no functions in standard C for e.g. lis-
ting the contents of a directory.

C also has to run on systems without files and on systems without a
"command processor" but it has file operations and the 'system'
function. I don't see a technical reason why they could be provided
as standard. They simply would not do anything if there were no
directories.

--
Ben.
 

 
jacob navia
PostPosted: Fri Jun 27, 2008 12:33 pm    Post subject: Re: directories
       
Ben Bacarisse wrote:
Quote:
jt@toerring.de (Jens Thoms Toerring) writes:

sid <kingsiddharth@gmail.com> wrote:
I want to write a C program that can read directories (say list them
as well).
I found out that we could use an API provided by dirent.h header file,
but I am not too keen on using the API. I want to access it directly
without any API. Any help is welcome.
Since C programs also have to run on machines were directories
don't exist there are no functions in standard C for e.g. lis-
ting the contents of a directory.

C also has to run on systems without files and on systems without a
"command processor" but it has file operations and the 'system'
function. I don't see a technical reason why they could be provided
as standard. They simply would not do anything if there were no
directories.


This is a typical situation. Here you have TWO choices:

Standardize targeting a high level platform. Platforms that
do not support the feature being standardized just return error
codes.

Standardize targeting the lowest level platform. This way
higher level platform users are remained that C is useful
for only low level platforms and should go to C++.

Easy isn't it?


--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
LINK
 

 
Ben Bacarisse
PostPosted: Fri Jun 27, 2008 1:08 pm    Post subject: Re: directories
       
jacob navia <jacob@nospam.com> writes:

Quote:
Ben Bacarisse wrote:
jt@toerring.de (Jens Thoms Toerring) writes:

sid <kingsiddharth@gmail.com> wrote:
I want to write a C program that can read directories (say list them
as well).
I found out that we could use an API provided by dirent.h header file,
but I am not too keen on using the API. I want to access it directly
without any API. Any help is welcome.
Since C programs also have to run on machines were directories
don't exist there are no functions in standard C for e.g. lis-
ting the contents of a directory.

C also has to run on systems without files and on systems without a
"command processor" but it has file operations and the 'system'
function. I don't see a technical reason why they could be provided
as standard. They simply would not do anything if there were no
directories.

This is a typical situation. Here you have TWO choices:

No, it is not binary choice.

Quote:
Standardize targeting a high level platform. Platforms that
do not support the feature being standardized just return error
codes.

You have to choose how "high level" you go. If you go too high level
almost all user programs get full of conditional tests for the
features. Too low-level and you miss out on useful functions. The
clever bit would be to pick exactly the right level that is useful for
a large range of applications and can be implemented "almost
everywhere".

Quote:
Standardize targeting the lowest level platform. This way
higher level platform users are remained that C is useful
for only low level platforms and should go to C++.

Eh? The last time I looked C++ does not have directory operations
either.

Quote:
Easy isn't it?

I think the choice is quite hard (at least I would not like to have to
make it and the defend it against all comers). In practise, most
people just go with ISO C + POSIX but I come form the world where that
is the norm. I am not sure what is gained by putting more functions
into the *language* standard.

--
Ben.
 

 
jacob navia
PostPosted: Fri Jun 27, 2008 1:31 pm    Post subject: Re: directories
       
Ben Bacarisse wrote:
Quote:

I think the choice is quite hard (at least I would not like to have to
make it and the defend it against all comers). In practise, most
people just go with ISO C + POSIX but I come form the world where that
is the norm. I am not sure what is gained by putting more functions
into the *language* standard.


Well almost all workstations OSes and many
embedded systems today have a directory structure

Simple abstractions like
opendir etc, as recommended by a simplified version of
POSIX would make programs more portable. At least
they would provide a natural way to do an iteration
trough a directory!



--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
LINK
 

Page 1 of 2 .:. Goto page 1, 2  Next

Google
 
Webnews.only-4-geeks.com

Windows Update | C++ | C | PHP | JavaScript | Photoshop | Programming | Windows 2000 | Python | Windows XP | Object | Flash | Flash - ActionScript | Paint Shop Pro | Excel | PowerPoint | Access | Word | Windows 98 | Internet Explorer 6.0 | CorelDraw12 | Java | XML | asm x86 | Linux Mandrake | Linux RedHat | Outlook |  | news from newsgroups |_ | s

Web Templates

Awesome Website Templates ©

nieruchomoƛci lublin LechoƄ Jan wiersze certyfikat energetyczny psy poker