summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThanos Apollo <[email protected]>2023-12-30 11:18:08 +0200
committerThanos Apollo <[email protected]>2023-12-30 11:18:08 +0200
commit9bd366ef4e33a70d205003e06cf92c6af3832b7c (patch)
tree7687b7f1f4de31acae42705efa22234a251f0569
parent425aea91564acda7bafa89f03710bfa3e7100c9d (diff)
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.
-rw-r--r--gnosis.el21
1 files changed, 21 insertions, 0 deletions
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)