The PathUtil structure
Author: John Reppy
Keywords: Standard ML, SML, SML/NJ Library

The SML of NJ Library
The `PathUtil` structure

The `PathUtil` structure provides support for searching for files in the file system using a list of possible locations. It is implemented using the SML Basis Library portable file-system mechanisms and, thus, it itself portable across different operating systems.

## Synopsis

    signature PATH_UTIL
    structure PathUtil : PATH_UTIL

## Interface

    val findFile : string list -> string -> string option

    val findFiles : string list -> string -> string list

    val existsFile : (string -> bool) -> string list -> string -> string option

    val allFiles : (string -> bool) -> string list -> string -> string list

    val findExe : string list -> string -> string option

## Description

`val findFile : string list -> string -> string option`

  `findFile paths name` returns `SOME path`, where `path` is a string of the form `"p/name"` and `p` is the first string in `paths` such that `path` exists. If no such file exists, then `NONE` is returned. If `name` is an absolute path, then `SOME name` is returned if it exists.

`val findFiles : string list -> string -> string list`

  `findFiles (paths, mode) name` returns a list of strings, such that each string `s` in the result has the form `"p/name"` with `p` in `paths` and the file named by `path` existing in the file system.

`val existsFile : (string -> bool) -> string list -> string -> string option`

  `existsFile pred paths name` returns `SOME path`, where `path` is a string of the form `"p/name"` and `p` is the first string in `paths` such that `path` exists and that `pred path` returns true. If no such file exists, then `NONE` is returned. If `name` is an absolute path, then `SOME name` is returned if it exists and satisfies the predicate.

`val allFiles : (string -> bool) -> string list -> string -> string list`

  `allFiles pred paths name` returns a list of strings, such that each string `s` in the result has the form `"p/name"` with `p` in `paths`, the file named by `path` existing in the file system, and `pred path` returns `true`. The order of the path list is preserved in the result. If `name` is an absolute path, then the list `[name]` is returned if `name` exists and satisfies the predicate.

`val findExe : string list -> string -> string option`

  `findExe paths name` searches `paths` for an executable file with the given name. This expression is equivalent to

      existsFile (fn p => OS.FileSys.access(p, [OS.FileSys.A_EXEC])) paths name

## See Also

`UnixPath`, The Util Library

SML/NJ Version 110.99.6 (September 19, 2024)
Last updated 2024-09-18 22:36:43 UTC