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