file-system.scm 728 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. (define-module (file-system)
  2. #:export (file?
  3. directory?
  4. readable?
  5. readable-file?
  6. readable-directory?
  7. file-size-in-bytes))
  8. (define file?
  9. (λ (path)
  10. (and (file-exists? path)
  11. (eq? (stat:type (stat path)) 'regular))))
  12. (define directory?
  13. (λ (path)
  14. (and (file-exists? path)
  15. (eq? (stat:type (stat path)) 'directory))))
  16. (define readable?
  17. (λ (path)
  18. (access? path R_OK)))
  19. (define readable-file?
  20. (λ (path)
  21. (and (readable? path)
  22. (file? path))))
  23. (define readable-directory?
  24. (λ (path)
  25. (and (readable? path)
  26. (directory? path))))
  27. (define file-size-in-bytes
  28. (λ (path)
  29. (stat:size (stat path))))