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
+22.2k Golang : Generate MD5 checksum of a file
+3.4k Javascript : How to show different content with noscript?
+4.2k PHP : See installed compiled-in-modules
+10.6k Golang : Gorilla web tool kit secure cookie example
+10.4k Golang : Convert decimal number(integer) to IPv4 address
+15.8k Golang : Get future or past hours, minutes or seconds
+4k Linux/Unix/MacOSX : Find out which application is listening to port 80 or use which IP version
+19.7k Golang : Get password from console input without echo or masked
+5.8k Golang : Takes a plural word and makes it singular
+5.9k Golang : A simple forex opportunities scanner
+16.2k Golang : [json: cannot unmarshal object into Go value of type]