Walk a directory/Recursively: Difference between revisions
Content deleted Content added
→{{header|TXR}}: Added. |
→{{header|TXR}}: Fix typo with better wording; move side note to end. |
||
Line 2,061: | Line 2,061: | ||
TXR wraps and exposes the POSIX <code>nftw</code> function, which is demonstrated here. This function encapsulates a tree walk, and uses callbacks to inform the program of visited filesystem tree nodes, and of error situations. We can use a <code>lambda</code> for the code walk, or wrap the invocation of <code>ftw</code> with a macro which hides the <code>lambda</code> syntax. |
TXR wraps and exposes the POSIX <code>nftw</code> function, which is demonstrated here. This function encapsulates a tree walk, and uses callbacks to inform the program of visited filesystem tree nodes, and of error situations. We can use a <code>lambda</code> for the code walk, or wrap the invocation of <code>ftw</code> with a macro which hides the <code>lambda</code> syntax. |
||
⚫ | |||
Here we use the <code>build</code> macro for procedural list building to gather all of the |
Here we use the <code>build</code> macro for procedural list building to gather all of the found paths into a list, which is implicitly returned. The callback is an explicit <code>lambda</code>: |
||
<lang txrlisp>(build (ftw "." (lambda (path type stat level base) |
<lang txrlisp>(build (ftw "." (lambda (path type stat level base) |
||
Line 2,100: | Line 2,099: | ||
The <code>type</code>, <code>stat</code>, <code>level</code> and <code>base</code> callback arguments we are ignoring closely follow those of the POSIX C <code>nftw</code> function. <code>type</code> is a type code which indicates the kind of item visited: file, directory; <code>stat</code> is a Lisp version of <code>struct stat</code>, providing various information about the filesystem object: permissions, timestamps, inode number, etc. |
The <code>type</code>, <code>stat</code>, <code>level</code> and <code>base</code> callback arguments we are ignoring closely follow those of the POSIX C <code>nftw</code> function. <code>type</code> is a type code which indicates the kind of item visited: file, directory; <code>stat</code> is a Lisp version of <code>struct stat</code>, providing various information about the filesystem object: permissions, timestamps, inode number, etc. |
||
⚫ | |||
=={{header|UNIX Shell}}== |
=={{header|UNIX Shell}}== |