File and directory paths are specified as strings. Since the syntax for pathnames can vary across platforms (e.g., under Unix, directories are separated by ``/'' while the Mac uses ``:''), MzScheme provides tools for portably constructing and deconstructing pathnames.
Most MzScheme primitives that take pathnames perform an expansion on
the pathname before using it. Under Unix, a user directory
specification using ``
'' is expanded. Under MacOS, file and
folder aliases are resolved to real pathnames. Procedures that build
paths or merely check the form of a pathname do not perform this
expansion.
Each subpath and base can optionally end in a directory separator. If the last subpath ends in a separator, it is included in the resulting pathname.
Under MacOS, if a subpath argument does not begin with a colon, one is added automatically. This means that subpath arguments are never interpreted as absolute paths under MacOS. For other platforms, if an absolute path is provided for any subpath, then the exn:i/o:filesystem:filename exception is raised.
The following examples assume that the current directory is ``/home/joeuser'' for Unix examples and ``My Disk:Joe's Files'' for MacOS examples.
(define p1 (build-path (current-directory) "src" "scheme"))
; Unix: p1 => "/home/joeuser/src/scheme"
; MacOS: p1 => "My Disk:Joe's Files:src:scheme"
(define p2 (build-path 'up 'up "docs" "MzScheme"))
; Unix: p2 => "../../docs/MzScheme"
; MacOS: p2 => ":::docs:MzScheme"
(build-pathname p2 p1)
; Unix: raises exn:i/o:filesystem:filename because p1 is absolute
; MacOS: => ":::docs:MzScheme:My Disk:Joe's Files:src:scheme"
(build-pathname p1 p2)
; Unix: => "/home/joeuser/src/scheme/../../docs/MzScheme"
; MacOS: => "My Disk:Joe's Files:src:scheme:::docs:MzScheme"