(module file mzscheme
(require "byteslike.ss"
"pathlike.ss"
"error.ss"
(lib "list.ss")
(lib "file.ss"))
(provide (all-defined))
(define (path-wrt-path base path)
(if (absolute-path? path)
(pathlike->path path)
(build-path base path)))
(define (replace-file-extension file new-ext)
(path-replace-suffix (pathlike->path file)
(byteslike-append "." new-ext)))
(define (pathlike-append . pathlikes)
(bytes->path (apply bytes-append (map pathlike->bytes pathlikes))))
(define (touch file)
(unless (file-exists? file)
(close-output-port (open-output-file file 'error))))
(define (check-file-exists name path)
(unless (file-exists? path)
(raise-file-not-found name path)))
(define (directory-list/sorted . args)
(map bytes->path
(quicksort (map pathlike->bytes (apply directory-list args))
bytes<?)))
(define (directory-list/paths directory)
(map (lambda (entry) (path-wrt-path directory entry))
(directory-list/sorted directory)))
(define (directory-list/absolute directory)
(let ((base (path-wrt-path (current-directory) directory)))
(map (lambda (entry) (build-absolute-path base entry))
(directory-list/sorted directory))))
(define (newer? a b)
(and (file-exists? a)
(or (not (file-exists? b))
(>= (file-or-directory-modify-seconds a)
(file-or-directory-modify-seconds b)))))
)