Skip to main content

fs.exists

Check whether a filesystem path resolves.

Usage​

fs.exists(path)
path
The file or directory to check. Symlinks are followed.

Returns True for an existing path and False for a missing path or dangling symlink. Other errors, including permission failures and symlink loops, raise an error instead of returning False. A successful check does not guarantee that a later filesystem operation will succeed: the filesystem can change.

if not fs.exists("config.json"):
errors.build("Missing config.json").with_hint("Create the project configuration.").fail()

Relative paths resolve against the script's working directory, including when called from a loaded module. Absolute paths are used as given. These functions inspect the local filesystem; they do not isolate access to the repository. Calls honor cancellation before and after the filesystem operation.

See reading files and Git hooks.