list-current-directory.scm 628 B

123456789101112131415161718192021222324252627282930
  1. (use-modules
  2. ;; ftw stands for file-tree-walk
  3. ;; for file-system-tree
  4. (ice-9 ftw)
  5. ;; for match-lambda
  6. (ice-9 match))
  7. ;; from:
  8. ;; https://www.gnu.org/software/guile/manual/html_node/File-Tree-Walk.html
  9. (define remove-stat
  10. ;; Remove the `stat' object the `file-system-tree' provides
  11. ;; for each file in the tree.
  12. (match-lambda
  13. ((name stat) ; flat file
  14. name)
  15. ((name stat children ...) ; directory
  16. (list name (map remove-stat children)))))
  17. (define list-dir
  18. (λ (path-to-dir)
  19. (remove-stat (file-system-tree path-to-dir))))
  20. (display
  21. (simple-format
  22. #f "~a\n"
  23. (list-dir ".")))