hugo/docs/content/en/functions/os/FileExists.md
Bjørn Erik Pedersen 5fd1e74903
Merge commit '9b0050e9aabe4be65c78ccf292a348f309d50ccd' as 'docs'
```
git subtree add --prefix=docs/ https://github.com/gohugoio/hugoDocs.git master --squash
```

Closes #11925
2024-01-27 10:48:57 +01:00

1.2 KiB

title description categories keywords action aliases
os.FileExists Reports whether the file or directory exists.
aliases related returnType signatures
fileExists
functions/os/Getenv
functions/os/ReadDir
functions/os/ReadFile
functions/os/Stat
bool
os.FileExists PATH
/functions/fileexists

The os.FileExists function attempts to resolve the path relative to the root of your project directory. If a matching file or directory is not found, it will attempt to resolve the path relative to the contentDir. A leading path separator (/) is optional.

With this directory structure:

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

The function returns these values:

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