请教个问题,没搜到类似情况的。

no such file or directory
syscall.Umask(0)

绝对路径类似于 /Users/admin/xxx/blog/content/zh-CN/post/filedir/test

已有目录 /Users/admin/xxx/blog/content/zh-CN/post 的权限也是 3 个 rwx ,自己在 shell 操作创建也是没问题。

因为拼接的路径,后边几级目录不确定,不至于每次创建一级,就调用个 os.Chmod 吧。。。


官方文档 func WriteFile(name string, data []byte, perm FileMode) error

WriteFile writes data to the named file, creating it if necessary. If the file does not exist, WriteFile creates it with permissions perm (before umask); otherwise WriteFile truncates it before writing, without changing permissions.

err := os.WriteFile("testdata/hello", []byte("Hello, Gophers!"), 0666)
if err != nil {
log.Fatal(err)
}