Skip to main content

fs.resolve

Resolve a path to an absolute path without touching the filesystem.

Usage​

fs.resolve(path)
path
The path to resolve. A leading ~ expands to the home directory. A relative path resolves against the script's working directory. An empty path fails.

Returns the absolute, cleaned path as a string. The path does not need to exist: fs.resolve never reads the filesystem. It follows the same rules as every other fs.* function, and all of them accept a leading ~. ~user is not expanded and is treated as a relative name.

Use it to normalize a user-supplied path once, then check or read the result:

target = fs.resolve(env["TARGET_DIR"])
if not fs.exists(target):
errors.build("Target directory not found: " + target).with_hint("Create it or pass an existing directory.").fail()

Calls honor cancellation.

See fs.exists and reading files.