HUGO
Menu
GitHub 90498 stars Mastodon

os.FileExists

Reports whether the file or directory exists.
Syntax
os.FileExists PATH
Returns
bool
Alias
fileExists

Usage

The os.FileExists function reports whether the file or directory at the given PATH exists. The function resolves the path relative to the root of your project directory, then relative to the root of each module. If it does not find a matching file or directory, it resolves the path relative to the content directory of the unified file system. A leading path separator (/) is optional.

Examples

These examples use this content structure:

content/
├── about.md
├── contact.md
└── news/
    ├── article-1.md
    └── article-2.md

Paths relative to the project directory:

{{ os.FileExists "content" }} → true
{{ os.FileExists "content/news" }} → true
{{ os.FileExists "content/news/article-1" }} → false
{{ os.FileExists "content/news/article-1.md" }} → true

Paths relative to the content directory:

{{ os.FileExists "news" }} → true
{{ os.FileExists "news/article-1" }} → false
{{ os.FileExists "news/article-1.md" }} → true