你可以使用os.Stat()函数来检查文件夹是否存在。例如:


package main
import (
    "fmt"
    "os"
)
func main() {
    path := "/path/to/folder"
    if _, err := os.Stat(path); os.IsNotExist(err) {
        fmt.Println("Folder does not exist")
    } else {
        fmt.Println("Folder exists")
    }
}

在上述代码中,os.Stat()函数尝试获取文件夹的信息。如果返回的错误值表示文件夹不存在,则使用os.IsNotExist()函数检查这是否是因为文件夹确实不存在。如果是,则表明文件夹不存在,否则表明文件夹存在。