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
+7.8k Golang Hello World Example
+8.3k Useful methods to access blocked websites
+5.7k Unix/Linux : Get reboot history or check when was the last reboot date
+4.9k Golang : Constant and variable names in native language
+10.4k Golang : Create matrix with Gonum Matrix package example
+7.6k Golang : Convert(cast) io.Reader type to string
+13.9k Golang : How to check if a file is hidden?
+28.7k Golang : Detect (OS) Operating System
+15.5k Golang : Validate hostname
+14.3k Golang : How to pass map to html template and access the map's elements
+29.8k Golang : How to get HTTP request header information?
+27.8k Golang : Decode/unmarshal unknown JSON data type with map[string]interface