man > filefuncs(3am)

πŸ“ NAME

filefuncs β€” provide some file related functionality to gawk

πŸš€ Quick Reference

Use CaseCommandDescription
πŸ“‚ Change directorychdir("/some/directory")Change the current working directory
πŸ“Š Get file stats (no symlink follow)stat("/some/path", statdata)Get file information using lstat(2)
πŸ“Š Get file stats (follow symlinks)stat("/some/path", statdata, 1)Get file information using stat(2)
🌳 Traverse file hierarchyfts(pathlist, flags, filedata)Walk a file tree and collect data into an array
πŸ’Ύ Get filesystem statsstatvfs("/some/path", fsdata)Get filesystem information from statvfs(2)

πŸ“‹ SYNOPSIS

@load "filefuncs"

result = chdir("/some/directory")

result = stat("/some/path", statdata [, follow])

flags = or(FTS_PHYSICAL, ...)
result = fts(pathlist, flags, filedata)

result = statvfs("/some/path", fsdata)

πŸ“– DESCRIPTION

The filefuncs extension adds several functions that provide access to file-related facilities.

πŸ“‚ chdir()

The chdir() function is a direct hook to the chdir(2) system call to change the current directory. It returns zero upon success or less than zero upon error. In the latter case it updates ERRNO.

πŸ“Š stat()

The stat() function provides a hook into the stat(2) system call. It returns zero upon success or less than zero upon error. In the latter case it updates ERRNO. By default, it uses lstat(2). However, if passed a third argument, it uses stat(2), instead.

In all cases, it clears the statdata array. When the call is successful, stat() fills the statdata array with information retrieved from the filesystem, as follows:

🌳 fts()

The fts() function provides a hook to the fts(3) set of routines for traversing file hierarchies. Instead of returning data about one file at a time in a stream, it fills in a multi-dimensional array with data about each file and directory encountered in the requested hierarchies.

The arguments are as follows:

πŸ“ pathlist

An array of filenames. The element values are used; the index values are ignored.

🏴 flags

This should be the bitwise OR of one or more of the following predefined flag values. At least one of FTS_LOGICAL or FTS_PHYSICAL must be provided; otherwise fts() returns an error value and sets ERRNO.

πŸ“‹ filedata

The filedata array is first cleared. Then, fts() creates an element in filedata for every element in pathlist. The index is the name of the directory or file given in pathlist. The element for this index is itself an array. There are two cases.

The fts() function returns 0 if there were no errors. Otherwise it returns -1.

πŸ’Ύ statvfs()

The statvfs() function provides a hook into the statvfs(2) system call on systems that supply this system call. It returns zero upon success or less than zero upon error. In the latter case it updates ERRNO.

When the call is successful, statvfs() fills the fsdata array with information retrieved about the filesystem, as follows:

πŸ“Œ NOTES

The AWK fts() extension does not exactly mimic the interface of the fts(3) routines, choosing instead to provide an interface that is based on associative arrays, which should be more comfortable to use from an AWK program. This includes the lack of a comparison function, since gawk already provides powerful array sorting facilities. While an fts_read()-like interface could have been provided, this felt less natural than simply creating a multi-dimensional array to represent the file hierarchy and its information.

Nothing prevents AWK code from changing the predefined FTS_xx values, but doing so may cause strange results when the changed values are passed to fts().

πŸ› BUGS

There are many more file-related functions for which AWK interfaces would be desirable.

It's not clear why I thought adding FTS_SKIP was a good idea.

πŸ’‘ EXAMPLE

See test/fts.awk in the gawk distribution for an example.

πŸ“š SEE ALSO

GAWK: Effective AWK Programming, fnmatch(3am), fork(3am), inplace(3am), ordchr(3am), readdir(3am), readfile(3am), revoutput(3am), rwarray(3am), time(3am).

chdir(2), fts(3), stat(2), statvfs(2).

πŸ‘€ AUTHOR

Arnold Robbins, arnold AT skeeve.com.

πŸ“„ COPYING PERMISSIONS

Copyright Β© 2012, 2013, 2018, 2019, Free Software Foundation, Inc.

Permission is granted to make and distribute verbatim copies of this manual page provided the copyright notice and this permission notice are preserved on all copies.

Permission is granted to copy and distribute modified versions of this manual page under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one.

Permission is granted to copy and distribute translations of this manual page into another language, under the above conditions for modified versions, except that this permission notice may be stated in a translation approved by the Foundation.

filefuncs(3am)
πŸ“ NAME πŸš€ Quick Reference πŸ“‹ SYNOPSIS πŸ“– DESCRIPTION
πŸ“‚ chdir() πŸ“Š stat() 🌳 fts() πŸ’Ύ statvfs()
πŸ“Œ NOTES πŸ› BUGS πŸ’‘ EXAMPLE πŸ“š SEE ALSO πŸ‘€ AUTHOR πŸ“„ COPYING PERMISSIONS

Generated by phpman v4.10.0-7-g98e9fd5 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-09-15 20:23 @216.73.216.158
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!

^_top_^