1--- 2title: "fileExists" 3linktitle: "fileExists" 4date: 2017-08-31T22:38:22+02:00 5description: Checks for file or directory existence. 6publishdate: 2017-08-31T22:38:22+02:00 7lastmod: 2021-11-26 8categories: [functions] 9menu: 10 docs: 11 parent: "functions" 12signature: ["os.FileExists PATH","fileExists PATH"] 13workson: [] 14hugoversion: 15relatedfuncs: ['os.ReadDir','os.ReadFile','os.Stat'] 16deprecated: false 17aliases: [] 18--- 19The `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. 20 21With this directory structure: 22 23```text 24content/ 25├── about.md 26├── contact.md 27└── news/ 28 ├── article-1.md 29 └── article-2.md 30``` 31 32The function returns these values: 33 34```go-html-template 35{{ os.FileExists "content" }} --> true 36{{ os.FileExists "content/news" }} --> true 37{{ os.FileExists "content/news/article-1" }} --> false 38{{ os.FileExists "content/news/article-1.md" }} --> true 39{{ os.FileExists "news" }} --> true 40{{ os.FileExists "news/article-1" }} --> false 41{{ os.FileExists "news/article-1.md" }} --> true 42``` 43