From e7492af2bd0c8cb631ad30b2c793928c61e41a73 Mon Sep 17 00:00:00 2001 From: cage Date: Sun, 23 Jan 2022 16:02:47 +0100 Subject: [PATCH] - added 'fs:collect-tree'. --- src/filesystem-utils.lisp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/filesystem-utils.lisp b/src/filesystem-utils.lisp index ce4331f..b6b473c 100644 --- a/src/filesystem-utils.lisp +++ b/src/filesystem-utils.lisp @@ -146,6 +146,23 @@ (setf all-paths (sort all-paths #'string<)) all-paths)) +(defun collect-tree (unvisited-dirs &optional (accum '())) + (declare (optimize (debug 0) (speed 3))) + (cond + ((null unvisited-dirs) + accum) + (t + (let* ((children (collect-children (first unvisited-dirs))) + (files (remove-if #'directory-exists-p children)) + (directories (mapcar (lambda (a) (text-utils:strcat a "/")) + (remove-if (lambda (a) + (or (file-exists-p a) + (backreference-dir-p a) + (loopback-reference-dir-p a))) + children)))) + (collect-tree (append (rest unvisited-dirs) directories) + (append files accum)))))) + (defun backreference-dir-p (path) (string= (path-last-element path) ".."))