info > FILEFUNCS(3am)

```html

FILEFUNCS(3am) — GNU Awk Extension Modules

🚀 Quick Reference

Use Case Command Description
Change Directory chdir("/some/directory") 🔀 Change the current directory via chdir(2).
Get File/Directory Stats stat("/some/path", statdata [, follow]) 📊 Retrieve filesystem information (wraps stat(2)/lstat(2)).
Traverse File Hierarchy fts(pathlist, flags, filedata) 🧭 Traverse file hierarchies using fts(3), returning a multi-dimensional array.
Get Filesystem Stats statvfs("/some/path", fsdata) 💾 Retrieve filesystem statistics via statvfs(2).

📛 NAME

filefuncs — provide some file related functionality to gawk

📝 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:

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 (C) 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)
FILEFUNCS(3am) — GNU Awk Extension Modules 🚀 Quick Reference 📛 NAME 📝 SYNOPSIS 📖 DESCRIPTION
📂 chdir() 📊 stat() 🧭 fts() 💾 statvfs()
📝 NOTES 🐛 BUGS 💡 EXAMPLE 📚 SEE ALSO ✍️ AUTHOR 📄 COPYING PERMISSIONS

Generated by phpman v4.9.26-1-g511901d Author: Che Dong Under GNU General Public License
2026-08-06 18:09 @216.73.216.79
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format