;;;; directory-utils.checks.scm ;;;; Kon Lovett, Mar '24 ;;;; Kon Lovett, Aug '10 ;; Issues ;; ;; - Need a routine that provides filename and stat info to the fold func. ;; stat info: Posix + platform specific: ;; Windows Hidden attribute ... ;; macOS birthtime ... ;; ;; - Windows support is bit of a joke. ;; ;; - minimal checks via "type-punning" (module (directory-utils checks) (;export pathname? check-pathname error-pathname filename? check-filename error-filename dirname? check-dirname error-dirname ;existence check documented check-directory error-directory) (import scheme utf8) (import (chicken base)) (import (chicken type)) (import (only (chicken file) directory-exists?)) (import (only type-checks-basic define-check+error-type)) (import (only (chicken pathname) decompose-pathname)) (include-relative "directory-utils.types") ;NOTE do not type these as 'predicate', ex: (: filename? (* -> boolean : filename)) ;since the compiler will treat a literal ".." as meeting the criteria at compile time! (: dirname? (* --> boolean)) (: check-dirname (* * #!optional * -> dirname)) (: error-dirname (* * #!optional * -> void)) ;uses directory? or directory-exists? (: check-directory (* * #!optional * -> dirname)) (: error-directory (* * #!optional * -> void)) (: pathname? (* --> boolean)) (: check-pathname (* * #!optional * -> pathname)) (: error-pathname (* * #!optional * -> void)) (: filename? (* --> boolean)) (: check-filename (* * #!optional * -> filename)) (: error-filename (* * #!optional * -> void)) ;;(std-prelde) (define (boolean obj) (and obj #t)) ;; ; Detecting only an extension is impossible with string pathnames ; - dotted file ; ; A null is not a name here (define (dirname? obj) (and (string? obj) (receive (dir fil ext) (decompose-pathname obj) (boolean dir))) ) (define-check+error-type dirname) ;existence check documented (define-check+error-type directory directory-exists?) (define (pathname? obj) (and (string? obj) (receive (dir fil ext) (decompose-pathname obj) (boolean (or dir fil)))) ) (define-check+error-type pathname) (define (filename? obj) (and (string? obj) (receive (dir fil ext) (decompose-pathname obj) (boolean (and (not dir) fil)))) ) (define-check+error-type filename) ) ;(directory-utils checks)