Outdated egg!

This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for the CHICKEN 5 version of this egg, if it exists.

If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.

  1. Outdated egg!
  2. filepath
    1. Description
    2. Library Procedures
      1. Platform Flags
      2. Path Separators
      3. Search Path
      4. Extension procedures
      5. Drive procedures
      6. Operations on a file path
      7. Trailing Separators
      8. File Name Normalization and Predicates
    3. Requires
    4. Version History
    5. License

filepath

Description

The filepath library contains procedures for cross-platform parsing and manipulation of file paths. It supports both Windows and POSIX paths, including Windows share paths.

Library Procedures

Platform Flags

[procedure] (filepath:posix [BOOL]) => BOOL

If invoked without arguments, this procedure returns whether the library procedures assume POSIX-style paths or not. Invoking the procedure with a boolean argument disables or enables POSIX-style paths. If set to false, the library procedures assume Windows-style paths.

[procedure] (filepath:is-windows?) => BOOL

Convenience function that returns the inverse of (filepath:posix).

[procedure] (filepath:is-posix?) => BOOL

Convenience function that returns the result of (filepath:posix).

Path Separators

[procedure] (filepath:path-separator) => CHAR

The character that separates directories. On platforms where more than one character is possible, this procedure returns the default one.

[procedure] (filepath:path-separator-set) => CHAR-SET

The set of all possible path separator characters.

[procedure] (filepath:is-path-separator? CHAR) => BOOL

A predicate that returns whether the given character is a path separator for the current platform.

[procedure] (filepath:search-path-separator) => CHAR

The character that is used to separate the entries in the PATH environment variable.

[procedure] (filepath:is-search-path-separator? CHAR) => BOOL

A predicate that returns whether the given character can be used a separator in the PATH environment variable.

[procedure] (filepath:ext-separator) => CHAR

The character that is used to separate file extensions.

[procedure] (filepath:is-ext-separator? CHAR) => BOOL

A predicate that returns whether the given character is a file extension separator.

Search Path

[procedure] (filepath:split-search-path STRING) => LIST

Splits a string on the search path separator character.

[procedure] (filepath:get-search-path) => STRING

Returns search path from the OS environment.

Extension procedures

[procedure] (filepath:split-extension PATH) => (NAME EXT)

Splits path on the last extension.

[procedure] (filepath:take-extension PATH) => EXT

Returns last extension of given path, or empty string.

[procedure] (filepath:replace-extension PATH EXT) => PATH

Replaces the last path extension with the given extension.

[procedure] (filepath:drop-extension PATH) => PATH

Removes last extension and extension separator preceding it.

[procedure] (filepath:add-extension PATH EXT) => PATH

Appends an extension to the given path.

[procedure] (filepath:has-extension? PATH) => BOOL

Returns true if the given path has an extension.

[procedure] (filepath:split-all-extensions PATH) => (NAME EXT)

Splits path on the first extension.

[procedure] (filepath:drop-all-extensions PATH) => PATH

Removes all extensions from the path.

[procedure] (filepath:take-all-extensions PATH) => EXT

Returns all extensions from the path.

Drive procedures

[procedure] filepath:split-drive

Splits a path into a Windows drive and a path. When in POSIX mode, / is treated as a drive.

[procedure] (filepath:join-drive DRIVE PATH) => PATH

Joins a drive and the rest of the path.

[procedure] (filepath:take-drive PATH) => DRIVE

Returns the drive of a path.

[procedure] (filepath:has-drive? PATH) => BOOL

Returns whether the given path has a drive.

[procedure] (filepath:drop-drive PATH) => PATH

Removes the drive from the given path.

[procedure] (filepath:is-drive? STRING) => BOOL

Returns true if the given string is a drive specification.

Operations on a file path

[procedure] (filepath:split-file-name PATH) => (DIR FILE)

Splits a path into directory and file.

[procedure] (filepath:take-file-name PATH) => FILE

Returns the filename component of a path.

[procedure] (filepath:replace-file-name PATH FILE) => PATH

Replaces the filename component of a path with the given one.

[procedure] (filepath:drop-file-name PATH) => PATH

Removes the filename component of a path.

[procedure] (filepath:take-base-name PATH) => STRING

Returns the base file name (no extension) of a path.

[procedure] (filepath:replace-base-name PATH BASE) => PATH

Replaces the base file name of a path with the given one.

[procedure] (filepath:take-directory PATH) => DIR

Returns the directory component of a path.

[procedure] (filepath:replace-directory PATH DIR) => PATH

Replaces the directory component of a path with the given one.

[procedure] (filepath:combine PATH1 PATH2) => PATH

Combines two paths. If the second path is absolute, then it returns the second.

[procedure] (filepath:split-path PATH) => LIST

Splits a path by the directory separator.

[procedure] (filepath:join-path LIST) => PATH

Joins path elements back together.

[procedure] filepath:split-directories

As split-path, but does not add trailing separators to each element.

Trailing Separators

[procedure] (filepath:has-trailing-path-separator? PATH) => BOOL
[procedure] (filepath:add-trailing-path-separator PATH) => PATH
[procedure] (filepath:drop-trailing-path-separator PATH) => PATH

File Name Normalization and Predicates

[procedure] (filepath:normalise PATH) => PATH
[procedure] (filepath:path-equal? PATH1 PATH2) => BOOL
[procedure] (filepath:make-relative ROOT PATH) => PATH
[procedure] (filepath:is-relative? PATH) => BOOL
[procedure] (filepath:is-absolute? PATH) => BOOL
[procedure] (filepath:is-valid? PATH) => BOOL
[procedure] (filepath:make-valid PATH) => PATH

Requires

Version History

License

Based on the Haskell FilePath library by Neil Mitchell.

Copyright 2008-2012 Ivan Raikov.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND THE CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.