Logo GenPRES

Directory Module

Walks up the directory tree from a start directory and returns the first directory that meets a condition or holds a given file, or None when no directory does. The module has the same name as the System.IO.Directory class and hides the class in a file that opens both, so the module calls the class by the full name System.IO.Directory.

Functions and values

Function or value Description

Directory.tryFindDirWithFile fileName startDir

Full Usage: Directory.tryFindDirWithFile fileName startDir

Parameters:
    fileName : string
    startDir : string

Returns: string option

The first directory at or above startDir that directly contains a file named fileName, probed by exact path.

fileName : string
startDir : string
Returns: string option

Directory.tryFindFileUpward fileName startDir

Full Usage: Directory.tryFindFileUpward fileName startDir

Parameters:
    fileName : string
    startDir : string

Returns: string option

The full path of the first file named fileName at or above startDir, or None when no ancestor holds one.

fileName : string
startDir : string
Returns: string option

Directory.tryFindParent fileToFind startDir

Full Usage: Directory.tryFindParent fileToFind startDir

Parameters:
    fileToFind : string
    startDir : string

Returns: string option

The first directory at or above startDir that contains a file whose name matches fileToFind ignoring case. Accepts a file as startDir and starts from its directory. Never throws.

The guard is per directory: one that cannot be enumerated (permissions) counts as "no match" and the walk continues upward.

fileToFind : string
startDir : string
Returns: string option

Directory.tryFindUpward found startDir

Full Usage: Directory.tryFindUpward found startDir

Parameters:
    found : string -> bool - Predicate tested against each directory on the way up.
    startDir : string - The directory to start the upward search from.

Returns: string option The first matching directory, or None if none matches.

Walk up the directory tree from startDir (inclusive), returning the first directory for which found holds, or None when the filesystem root is reached.

found : string -> bool

Predicate tested against each directory on the way up.

startDir : string

The directory to start the upward search from.

Returns: string option

The first matching directory, or None if none matches.

Type something to start searching.