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
+16.2k Golang : How to implement two-factor authentication?
+6.6k Golang : How to solve "too many .rsrc sections" error?
+13.9k Golang : Chunk split or divide a string into smaller chunk example
+34.2k Golang : How to stream file to client(browser) or write to http.ResponseWriter?
+9k Golang : Generate random Chinese, Japanese, Korean and other runes
+6.7k Golang : Gargish-English language translator
+31.9k Golang : Convert []string to []byte examples
+12.1k Golang : 2 dimensional array example
+4.7k Javascript : How to get width and height of a div?
+16.5k Golang : Set up source IP address before making HTTP request
+8k Swift : Convert (cast) Character to Integer?
+6.7k Golang : Calculate BMI and risk category