Create directory in Go
In this short tutorial, we will learn how to create directory in platform independent manner. I.e we don't worry about the \
and /
part for *nix and Windows machines.
mkdir.go
package main
import (
//"fmt"
"os"
"path/filepath"
)
func main() {
// create a TestDir directory on current working directory
os.Mkdir("." + string(filepath.Separator) + "TestDir",0777)
}
The 0777
permission can be to liberal for some cases and you might want to change it for your production code.
References :
See also : Golang : File path independent of Operating System
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+8.9k Golang : Convert octal value to string to deal with leading zero problem
+22.4k Golang : Use regular expression to validate domain name
+6.5k Golang : Shuffle strings array
+4.4k Javascript : How to loop over and parse JSON data?
+7.9k Golang : automatically figure out array length(size) with three dots
+18.2k Golang : Delete item from slice based on index/key position
+11.8k Golang : Qt progress dialog example
+44.3k Golang : Marshal and unmarshal json.RawMessage struct example
+5.6k Golang : Derive cryptographic key from passwords with Argon2
+10.2k Golang : Post data with url.Values{}
+5k Golang : Extract unicode string from another unicode string example
+6.4k Golang : Rename part of filename