A simple recursive function can traverse all the files in the directory tree and pass another processing function. This function can take the file path as a parameter to determine how to handle it.
The following is a call example:
#!/usr/bin/newlisp (load "file.lsp")(define (show-file file-path) (println (string file-path ": " (file-info file-path))) )(FILE:recursive-access-dir "/opt/" show-file)(exit)
Recursive-access-DIR is a recursive function. Show-file is another function that displays the received file path and file-Info information.
(context ‘FILE)(define (recursive-access-dir dir-path file-op) (dolist (nde (directory dir-path {^[^.]})) (if (directory? (append dir-path nde)) (recursive-access-dir (append dir-path nde "/") file-op) (file-op (append dir-path nde)))))
Note:
The regular expression ^ [^.] indicates that only files or directories not starting with "." are searched, so "." and "." are excluded ..
This recursive algorithm is a depth-first algorithm. Once a directory is found, all the paths under it will be traversed before returning to the beginning, and then processing the next sibling directory.
Newlisp recursive access to the directory tree