| 1 |
.TH READDIR 3am "Oct 30 2019" "Free Software Foundation" "GNU Awk Extension Modules" |
| 2 |
.SH NAME |
| 3 |
readdir \- directory input parser for gawk |
| 4 |
.SH SYNOPSIS |
| 5 |
.ft CW |
| 6 |
@load "readdir" |
| 7 |
.ft R |
| 8 |
.SH DESCRIPTION |
| 9 |
The |
| 10 |
.I readdir |
| 11 |
extension |
| 12 |
adds an input parser for directories. |
| 13 |
.PP |
| 14 |
When this extension is in use, instead of skipping directories named |
| 15 |
on the command line (or with |
| 16 |
.BR getline ), |
| 17 |
they are read, with each entry returned as a record. |
| 18 |
.PP |
| 19 |
The record consists of three fields. The first two are the inode number and the |
| 20 |
filename, separated by a forward slash character. |
| 21 |
On systems where the directory entry contains the file type, the record |
| 22 |
has a third field which is a single letter indicating the type of the |
| 23 |
file: |
| 24 |
.B f |
| 25 |
for file, |
| 26 |
.B d |
| 27 |
for directory, |
| 28 |
.B b |
| 29 |
for a block device, |
| 30 |
.B c |
| 31 |
for a character device, |
| 32 |
.B p |
| 33 |
for a FIFO, |
| 34 |
.B l |
| 35 |
for a symbolic link, |
| 36 |
.B s |
| 37 |
for a socket. |
| 38 |
.PP |
| 39 |
On systems without the file type information, the extension falls back |
| 40 |
to calling |
| 41 |
.IR stat (2), |
| 42 |
in order to provide the information. |
| 43 |
Thus the third field should never be |
| 44 |
.BR u . |
| 45 |
.PP |
| 46 |
By default, if a directory cannot be opened (due to permission problems, |
| 47 |
for example), |
| 48 |
.I gawk |
| 49 |
will exit. |
| 50 |
As with regular files, this situation can be handled using a |
| 51 |
.B BEGINFILE |
| 52 |
rule that checks |
| 53 |
.B ERRNO |
| 54 |
and prints an error or otherwise handles the problem. |
| 55 |
.\" .SH BUGS |
| 56 |
.SH EXAMPLE |
| 57 |
.ft CW |
| 58 |
.nf |
| 59 |
@load "readdir" |
| 60 |
\&... |
| 61 |
BEGIN { FS = "/" } |
| 62 |
{ print "file name is", $2 } |
| 63 |
.fi |
| 64 |
.ft R |
| 65 |
.SH "SEE ALSO" |
| 66 |
.IR "GAWK: Effective AWK Programming" , |
| 67 |
.IR filefuncs (3am), |
| 68 |
.IR fnmatch (3am), |
| 69 |
.IR fork (3am), |
| 70 |
.IR inplace (3am), |
| 71 |
.IR ordchr (3am), |
| 72 |
.IR readfile (3am), |
| 73 |
.IR revoutput (3am), |
| 74 |
.IR rwarray (3am), |
| 75 |
.IR time (3am). |
| 76 |
.PP |
| 77 |
.IR opendir (3), |
| 78 |
.IR readdir (3), |
| 79 |
.IR stat (2). |
| 80 |
.SH AUTHOR |
| 81 |
Arnold Robbins, |
| 82 |
.BR [email protected] . |
| 83 |
.SH COPYING PERMISSIONS |
| 84 |
Copyright \(co 2012, 2013, 2018, 2019 |
| 85 |
Free Software Foundation, Inc. |
| 86 |
.PP |
| 87 |
Permission is granted to make and distribute verbatim copies of |
| 88 |
this manual page provided the copyright notice and this permission |
| 89 |
notice are preserved on all copies. |
| 90 |
.ig |
| 91 |
Permission is granted to process this file through troff and print the |
| 92 |
results, provided the printed document carries copying permission |
| 93 |
notice identical to this one except for the removal of this paragraph |
| 94 |
(this paragraph not being relevant to the printed manual page). |
| 95 |
.. |
| 96 |
.PP |
| 97 |
Permission is granted to copy and distribute modified versions of this |
| 98 |
manual page under the conditions for verbatim copying, provided that |
| 99 |
the entire resulting derived work is distributed under the terms of a |
| 100 |
permission notice identical to this one. |
| 101 |
.PP |
| 102 |
Permission is granted to copy and distribute translations of this |
| 103 |
manual page into another language, under the above conditions for |
| 104 |
modified versions, except that this permission notice may be stated in |
| 105 |
a translation approved by the Foundation. |
| 106 |
.\" vim: set filetype=nroff : |