Files
hugo/docs/content/en/functions/fileExists.md
2021-12-08 08:54:25 +01:00

1.3 KiB

title, linktitle, date, description, publishdate, lastmod, categories, menu, signature, workson, hugoversion, relatedfuncs, deprecated, aliases
title linktitle date description publishdate lastmod categories menu signature workson hugoversion relatedfuncs deprecated aliases
fileExists fileExists 2017-08-31T22:38:22+02:00 Checks for file or directory existence. 2017-08-31T22:38:22+02:00 2021-11-26
functions
docs
parent
functions
os.FileExists PATH
fileExists PATH
os.ReadDir
os.ReadFile
os.Stat
false

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]({{< relref "getting-started/configuration#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:

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