Re: [gtk-list] Re: General C question - file attributes
- From: Norbert Bladt <abladtn autelca ascom ch>
- To: gtk-list redhat com
- Subject: Re: [gtk-list] Re: General C question - file attributes
- Date: Mon, 16 Aug 1999 08:07:14 +0200
Emmanuel DELOGET wrote:
>
> >On Sun, Aug 15, 1999 at 09:25:55AM -0400, John C Atkeson wrote:
> >>
> >> I'm reading directories with opendir, readdir and closedir. Um... how
> >I was looking for these... glad I read your question.
> >> do I detect file attributes, specifically how to distinguish files from
> >> sub-directories?
> >In the man page for readdir I found this:
> > struct dirent {
> > long d_ino; /* inode number */
> > off_t d_off; /* offset to the next dirent
> */
> > unsigned short d_reclen;/* length of this record */
> > unsigned char d_type; /* type of file */
> > char d_name[256]; /* filename */
> > };
> >That is what is returned from readdir, this is just a guess but I would
> think
> >that d_type is what you are looking for.
Right.
In the file /usr/include/sys/dirent.h (on your system it might be
in a different directory) there are some definitions for the
different type of files.
> Should probably be better to use the stat() function (don't remember the
> man page... Something like (2) - perhaps (3))
Did you ever try to use 'stat' on all files in a directory with, say,
300 entries ?
It is much slower than getting the types from readdir, which you
have to call, anyway.
Of course, it depends on the application whether you really need info
about every file in the directory !
But, e.g., to show just a filesystem tree, you just need to know
whether files do exist and whether there are any subdirectories.
HTH,
Norbert.
--
Norbert Bladt Payphone Management System Software Development
ascom Autelca AG
Worbstrasse 201 CH-3073 Guemligen, Switzerland
abladtn@autelca.ascom.ch VOICE: +41 31 999 6552, FAX: +41 31 999 6575
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]