On this page:
path-segments
make-paths-tree
path->directory
path->name
9.2

13 Enigma API: Path System Utilities🔗

 (require enigma/system/utils/path) package: enigma-app

procedure

(path-segments file-path)  (listof path?)

  file-path : path-string?
Splits file-path into its individual path segments.

procedure

(make-paths-tree file-path)  (listof path?)

  file-path : path-string?
Builds a list of all ancestor paths of file-path.

procedure

(path->directory file-path)  path?

  file-path : path-string?
Returns the parent directory of file-path.

procedure

(path->name file-path)  string?

  file-path : path-string?
Returns the final path component of file-path.

The source code of this module:

#lang racket/base
 
(require racket/contract/base)
(require racket/list)
 
(require threading)
 
(provide
 (contract-out
  [path-segments
   (-> path-string?
       (listof path?))]
  [make-paths-tree
   (-> path-string?
       (listof path?))]
  [path->directory
   (-> path-string?
       path?)]
  [path->name
   (-> path-string?
       string?)]))
 
(define path-segments
  (lambda~> expand-user-path
            path->complete-path
            simplify-path
            explode-path))
 
(define (make-paths-tree file-path)
  (for/fold ([paths '()])
            ([path-segment (path-segments file-path)])
    (cond
      [(null? paths)
       (list path-segment)]
      [else
       (define last-used-path (car paths))
       (cons (build-path last-used-path path-segment) paths)])))
 
(define path->directory
  (lambda~> path-segments
            reverse
            cdr
            reverse
            (apply build-path _)))
 
(define path->name
  (lambda~> path-segments
            last
            path->string))