hugo/docs/content/en/functions/os/FileExists.md
2023-10-20 09:43:56 +02:00

1.2 KiB

title linkTitle description categories keywords menu function relatedFunctions aliases
os.FileExists fileExists Reports whether the file or directory exists.
functions
docs
parent
functions
aliases returnType signatures
fileExists
bool
os.FileExists PATH
os.FileExists
os.Getenv
os.ReadDir
os.ReadFile
os.Stat
/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:

{{ 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