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
+10.5k Swift : Convert (cast) Float to String
+5.9k Golang : Calculate BMI and risk category
+6.2k Nginx : How to block user agent ?
+5.8k Default cipher that OpenSSL used to encrypt a PEM file
+10.1k Golang : Characters limiter example
+11.4k Golang : Remove or trim extra comma from CSV
+21.8k Golang : Randomly pick an item from a slice/array example
+16.5k Golang : Read data from config file and assign to variables
+6.5k Golang : Hue, Saturation and Value(HSV) with OpenCV example
+23.3k Golang : GORM read from database example
+6.8k Golang : Grayscale Image
+26k PHP : Count number of JSON items/objects