gawk: Extension Sample Readdir
1
1 16.7.6 Reading Directories
1 --------------------------
1
1 The 'readdir' extension adds an input parser for directories. The usage
1 is as follows:
1
1 @load "readdir"
1
1 When this extension is in use, instead of skipping directories named
1 on the command line (or with 'getline'), they are read, with each entry
1 returned as a record.
1
1 The record consists of three fields. The first two are the inode
1 number and the file name, separated by a forward slash character. On
1 systems where the directory entry contains the file type, the record has
1 a third field (also separated by a slash), which is a single letter
1 indicating the type of the file. The letters and their corresponding
1 file types are shown in ⇒Table 16.3 table-readdir-file-types.
1
1 Letter File type
1 --------------------------------------------------------------------------
1 'b' Block device
1 'c' Character device
1 'd' Directory
1 'f' Regular file
1 'l' Symbolic link
1 'p' Named pipe (FIFO)
1 's' Socket
1 'u' Anything else (unknown)
1
1 Table 16.3: File types returned by the 'readdir' extension
1
1 On systems without the file type information, the third field is
1 always 'u'.
1
1 NOTE: On GNU/Linux systems, there are filesystems that don't
1 support the 'd_type' entry (see the readdir(3) manual page), and so
1 the file type is always 'u'. You can use the 'filefuncs' extension
1 to call 'stat()' in order to get correct type information.
1
1 Here is an example:
1
1 @load "readdir"
1 ...
1 BEGIN { FS = "/" }
1 { print "file name is", $2 }
1