file-system.scm 976 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. (library (file-system)
  2. (export file?
  3. directory?
  4. readable?
  5. readable-file?
  6. readable-directory?
  7. file-size-in-bytes)
  8. (import (rnrs base)
  9. (only (guile)
  10. lambda* λ
  11. stat
  12. stat:type
  13. stat:size
  14. access?
  15. file-exists?
  16. R_OK))
  17. (define file?
  18. (λ (path)
  19. (and (file-exists? path)
  20. (eq? (stat:type (stat path)) 'regular))))
  21. (define directory?
  22. (λ (path)
  23. (and (file-exists? path)
  24. (eq? (stat:type (stat path)) 'directory))))
  25. (define readable?
  26. (λ (path)
  27. (access? path R_OK)))
  28. (define readable-file?
  29. (λ (path)
  30. (and (readable? path)
  31. (file? path))))
  32. (define readable-directory?
  33. (λ (path)
  34. (and (readable? path)
  35. (directory? path))))
  36. (define file-size-in-bytes
  37. (λ (path)
  38. (stat:size (stat path)))))