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
+9.2k Golang : Get SPF and DMARC from email headers to fight spam
+10.4k Golang : Check a web page existence with HEAD request example
+19.8k Golang : Close channel after ticker stopped example
+6.1k Golang : Shuffle array of list
+6.7k Golang : Totalize or add-up an array or slice example
+12.4k Golang : Split strings into command line arguments
+13.8k Golang : Set image canvas or background to transparent
+7.6k Golang : Convert source code to assembly language
+20.4k Golang : Convert seconds to human readable time format example
+24.2k Golang : Fix type interface{} has no field or no methods and type assertions example
+36.8k Golang : Validate IP address
+10.8k Golang : Bubble sort example