file-system.scm 955 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. (define file?
  17. (λ (path)
  18. (and (file-exists? path)
  19. (eq? (stat:type (stat path)) 'regular))))
  20. (define directory?
  21. (λ (path)
  22. (and (file-exists? path)
  23. (eq? (stat:type (stat path)) 'directory))))
  24. (define readable?
  25. (λ (path)
  26. (access? path R_OK)))
  27. (define readable-file?
  28. (λ (path)
  29. (and (readable? path)
  30. (file? path))))
  31. (define readable-directory?
  32. (λ (path)
  33. (and (readable? path)
  34. (directory? path))))
  35. (define file-size-in-bytes
  36. (λ (path)
  37. (stat:size (stat path)))))