fpreaddir

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

fpreaddir

Rainer Stratmann

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?

 Rainer
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: fpreaddir

Marco van de Voort
> 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.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: fpreaddir

Rainer Stratmann
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.

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?
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: fpreaddir

Marco van de Voort
> 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.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: fpreaddir

Marc Santhoff
In reply to this post by Rainer Stratmann
Am Donnerstag, den 01.05.2008, 16:54 +0200 schrieb Rainer Stratmann:

> 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


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: fpreaddir

Rainer Stratmann
Am Donnerstag, 1. Mai 2008 18:58 schrieb Marc Santhoff:
> 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.

> 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  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal