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
+5.5k Unix/Linux : How to test user agents blocked successfully ?
+5.9k Golang : Scan forex opportunities by Bollinger bands
+23.2k Find and replace a character in a string in Go
+18.6k Golang : Read input from console line
+8.2k Golang : Ackermann function example
+6.6k Get Facebook friends working in same company
+9k Golang : Temperatures conversion example
+14.4k Golang : Normalize unicode strings for comparison purpose
+12.7k Swift : Convert (cast) Int to String ?
+9.1k Golang : Web(Javascript) to server-side websocket example
+6.6k Fix sudo yum hang problem with no output or error messages
+27.5k Golang : Decode/unmarshal unknown JSON data type with map[string]interface