branch: master
commit 16390ac2b8c0622ae94d6917f2df0ca90d61ec55
Author: Stephen Leake <stephen_le...@stephe-leake.org>
Commit: Stephen Leake <stephen_le...@stephe-leake.org>

    In path-iterator, add new function and test
    
    * packages/path-iterator/path-iterator-test.el (path-iter-all-files): New
    test.
    
    * packages/path-iterator/path-iterator.el (path-iter-all-files): New.
---
 .../path-iterator-resources/alice-1/foo-file1.text    |  1 +
 .../bob-1/bob-2/foo-file2.text                        |  1 +
 .../bob-1/bob-3/foo-file3.text                        |  1 +
 packages/path-iterator/path-iterator-test.el          | 19 ++++++++++++++++++-
 packages/path-iterator/path-iterator.el               | 17 +++++++++++++++++
 5 files changed, 38 insertions(+), 1 deletion(-)

diff --git 
a/packages/path-iterator/path-iterator-resources/alice-1/foo-file1.text 
b/packages/path-iterator/path-iterator-resources/alice-1/foo-file1.text
new file mode 100644
index 0000000..d83a9f4
--- /dev/null
+++ b/packages/path-iterator/path-iterator-resources/alice-1/foo-file1.text
@@ -0,0 +1 @@
+alice-1/foo-file1.text
diff --git 
a/packages/path-iterator/path-iterator-resources/bob-1/bob-2/foo-file2.text 
b/packages/path-iterator/path-iterator-resources/bob-1/bob-2/foo-file2.text
new file mode 100644
index 0000000..6bd9bdb
--- /dev/null
+++ b/packages/path-iterator/path-iterator-resources/bob-1/bob-2/foo-file2.text
@@ -0,0 +1 @@
+bob-1/foo-file2.text
diff --git 
a/packages/path-iterator/path-iterator-resources/bob-1/bob-3/foo-file3.text 
b/packages/path-iterator/path-iterator-resources/bob-1/bob-3/foo-file3.text
new file mode 100644
index 0000000..2a3b1e9
--- /dev/null
+++ b/packages/path-iterator/path-iterator-resources/bob-1/bob-3/foo-file3.text
@@ -0,0 +1 @@
+bob-2/foo-file5.text
diff --git a/packages/path-iterator/path-iterator-test.el 
b/packages/path-iterator/path-iterator-test.el
index 09c01da..780e744 100644
--- a/packages/path-iterator/path-iterator-test.el
+++ b/packages/path-iterator/path-iterator-test.el
@@ -158,7 +158,7 @@ iterator built from PATH-NON-RECURSIVE, PATH-RECURSIVE, 
IGNORE-FUNCTION."
   (let ((default-directory path-iter-root-dir))
     (should
      (equal
-      (path-iter-to-truename
+      (path-iter--to-truename
        (list
        nil
        (concat path-iter-root-dir "/alice-1")))
@@ -168,5 +168,22 @@ iterator built from PATH-NON-RECURSIVE, PATH-RECURSIVE, 
IGNORE-FUNCTION."
 
   )))
 
+(ert-deftest path-iter-all-files ()
+  (let ((iter
+        (make-path-iterator
+         :user-path-non-recursive nil
+         :user-path-recursive (list path-iter-root-dir))))
+
+    (should
+     (equal
+      (path-iter-all-files iter)
+      (list
+       (concat path-iter-root-dir "/bob-1/bob-3/foo-file3.text")
+       (concat path-iter-root-dir "/bob-1/bob-2/foo-file2.text")
+       (concat path-iter-root-dir "/alice-1/foo-file1.text")
+       (concat path-iter-root-dir "/file-0.text")
+       )))
+    ))
+
 (provide 'path-iterator-test)
 ;;; path-iterator.el ends here
diff --git a/packages/path-iterator/path-iterator.el 
b/packages/path-iterator/path-iterator.el
index ca208e4..1c57ce3 100644
--- a/packages/path-iterator/path-iterator.el
+++ b/packages/path-iterator/path-iterator.el
@@ -285,5 +285,22 @@ Return a list of absolute filenames or nil if none found."
        (file-name-all-completions filename dir)))
     result))
 
+(defun path-iter-all-files (iter)
+  "Return all filenames in ITER (a `path-iterator' object."
+  (let (result)
+    (path-iter-restart iter)
+
+    (while (not (path-iter-done iter))
+      (let ((dir (path-iter-next iter)))
+       (mapc
+        (lambda (absfile)
+          (when (and (not (string-equal "." (substring absfile -1)))
+                     (not (string-equal ".." (substring absfile -2)))
+                     (not (file-directory-p absfile)))
+            (push absfile result)))
+        (directory-files dir t))
+       ))
+    result))
+
 (provide 'path-iterator)
 ;;; path-iterator.el ends here.

Reply via email to