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
+26.2k Golang : Convert IP address string to long ( unsigned 32-bit integer )
+22.4k Golang : Convert seconds to minutes and remainder seconds
+8k Golang : Gomobile init produce "iphoneos" cannot be located error
+14.3k Golang : Convert IP version 6 address to integer or decimal number
+5.9k Golang : Detect variable or constant type
+10.6k Golang : Generate 403 Forbidden to protect a page or prevent indexing by search engine
+6.2k Linux/Unix : Commands that you need to be careful about
+8.3k Golang : Qt splash screen with delay example
+10.3k Golang : Wait and sync.WaitGroup example
+4.9k HTTP common errors and their meaning explained
+5.4k Golang : Intercept, inject and replay HTTP traffics from web server