简体   繁体   中英

How to make a directory in Golang?

So I'm attempting to create a CMS where each user makes their own website and it is stored in a directory named as their choosing. However when I use

os.Mkdir("/Users/anonrose/Documents/goCode/src/github.com/anonrose/GoDataStructs/tests/myWebsite", os."some permission")

the "some permission" part is what I'm having troubles with. When I attempt to access the directory once it's been created I never have the correct permission. Is there a os.FileMode that I can use to set the permissions as read and write for anyone when I go to create the directory.

If you need to set explicit permission bits not listed here then use os.FileMode

os.Mkdir("/path/to/dir", os.FileMode(0522))

The least significant 9 bits of the uint32 represent the file permissions, so 0777 would be 511 for example.

I always use os.ModeDir :

package main
import "os"

func main() {
   os.Mkdir("March", os.ModeDir)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM