From 9bd366ef4e33a70d205003e06cf92c6af3832b7c Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sat, 30 Dec 2023 11:18:08 +0200 Subject: Add gnosis-directory-files Return a list of file paths as strings in DIR, filter results with REGEX. This funciton will be used to prompt user to select files, such as images. --- gnosis.el | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/gnosis.el b/gnosis.el index 9c1dc89..44e7100 100644 --- a/gnosis.el +++ b/gnosis.el @@ -453,6 +453,27 @@ Compare 2 strings, ignoring case and whitespace." (modified-str2 (downcase (replace-regexp-in-string "\\s-" "" str2)))) (string= modified-str1 modified-str2))) +(defun gnosis-directory-files (&optional dir regex) + "Return a list of file paths, relative to DIR directory. + +DIR is the base directory path from which to start the recursive search. +REGEX is the regular expression pattern to match the file names against. + +This function traverses the subdirectories of DIR recursively, +collecting file paths that match the regular expression. The file +paths are returned as a list of strings, with each string representing +a relative file path to DIR. + +By default, DIR value is `gnosis-images-dir' & REGEX value is \"^[^.]\"" + (let ((dir (or dir gnosis-images-dir)) + (regex (or regex "^[^.]"))) + (apply #'append + (cl-loop for path in (directory-files dir t directory-files-no-dot-files-regexp) + if (file-directory-p path) + collect (mapcar (lambda (file) (concat (file-relative-name path dir) "/" file)) + (gnosis-directory-files path regex)) + else if (string-match-p regex (file-name-nondirectory path)) + collect (list (file-relative-name path dir)))))) (defun gnosis-get-tags--unique () "Return a list of unique strings for tags in gnosis-db." (cl-loop for tags in (gnosis-select 'tags 'notes) -- cgit v1.2.3