Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2008-05

fpreaddir

6 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Rainer Stratmann
to Marco van de Voort: d_type being DT_UNKNOWN 0 DT_FIFO 1 DT_CHR 2 DT_DIR 4…
Marco van de Voort wrote 13 lines
d_type being DT_UNKNOWN 0 DT_FIFO 1 DT_CHR 2 DT_DIR 4 DT_BLK 6 DT_REG 8 DT_LNK 10 DT_SOCK 12 DT_WHT 14 But why do you not simply use findfirst/findnext? It's more portable.

The result of d_type is always 0 even if the entry is a directory.

Your question is not easy to answer.
In one way you are right, but I like to program as close to the os as possible.
Does findfirst/findnext also support these things like '*.pas' and file attributes?

Reply by email

Marco van de Voort
to Rainer Stratmann: fpreaddir -> http://www.freepascal.org/docs-html/rtl/baseunix/fpreaddir.html dirent…
Show quoted text 7 lines
fpreaddir -> http://www.freepascal.org/docs-html/rtl/baseunix/fpreaddir.html dirent record structure -> http://www.freepascal.org/docs-html/rtl/baseunix/dirent.html How do I know if the readed entry is a subdir?

d_type being

DT_UNKNOWN 0
DT_FIFO 1
DT_CHR 2
DT_DIR 4
DT_BLK 6
DT_REG 8
DT_LNK 10
DT_SOCK 12
DT_WHT 14

But why do you not simply use findfirst/findnext? It's more portable.

Reply by email

Marco van de Voort
to Rainer Stratmann: The result of d_type is always 0 even if the entry is a directory. Your question is not…
Show quoted text 8 lines
Am Donnerstag, 1. Mai 2008 17:17 schrieb Marco van de Voort: > DT_LNK 10 > DT_SOCK 12 > DT_WHT 14 > > But why do you not simply use findfirst/findnext? It's more portable. The result of d_type is always 0 even if the entry is a directory.

Then you'll have to do a fpstat to get additional data.

Your question is not easy to answer. In one way you are right, but I like to program as close to the os as possible.

In general findfirst/findnext is ok, unless you are creating e.g. an unix specific backup application that touches hundreds of thousands of files.

Does findfirst/findnext also support these things like '*.pas' and file attributes?

It supports wildcards. The file attributes are limited to the ones in searchrec, see help for more info.

Reply by email

Rainer Stratmann
to Marc Santhoff: What os are you on? I did "man readdir" and "man dirent" and found enough information. One
Marc Santhoff wrote
What os are you on?

Knoppix last DVD from heise

I did "man readdir" and "man dirent" and found enough information. One bit from the dirent manpage:

I did it also

...
Other than Linux, the d_type field is available mainly only on BSD systems. This field makes it possible to avoid the expense of calling stat() if further actions depend on the type of the file. ...

So I will use stat.

Show quoted text 14 lines
BUGS The usage of the member d_type of struct dirent is unportable as it is FreeBSD-specific. It also may fail on certain filesystems, for example the cd9660 filesystem. Maybe that's hitting you ... HTH, Marc _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Marc Santhoff
to Rainer Stratmann: The result of d_type is always 0 even if the entry is a directory. Your question is not…
Rainer Stratmann wrote 16 lines
Am Donnerstag, 1. Mai 2008 17:17 schrieb Marco van de Voort: > d_type being > > DT_UNKNOWN 0 > DT_FIFO 1 > DT_CHR 2 > DT_DIR 4 > DT_BLK 6 > DT_REG 8 > DT_LNK 10 > DT_SOCK 12 > DT_WHT 14 > > But why do you not simply use findfirst/findnext? It's more portable. The result of d_type is always 0 even if the entry is a directory.

What os are you on?

I did "man readdir" and "man dirent" and found enough information. One bit from the dirent manpage:

BUGS
The usage of the member d_type of struct dirent is unportable as it is FreeBSD-specific. It also may fail on certain filesystems, for example the cd9660 filesystem.

Maybe that's hitting you ...

HTH,
Marc

Reply by email