os.FileExists
语法
os.FileExists PATH
返回值
bool
别名
fileExists
os.FileExists
函数尝试解析相对于项目根目录的路径。如果找不到匹配的文件或目录,它将尝试解析相对于 contentDir
的路径。前导路径分隔符 (/
) 是可选的。
使用此目录结构
content/
├── about.md
├── contact.md
└── news/
├── article-1.md
└── article-2.md
该函数返回以下值
{{ 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