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
+11.8k Golang : Qt progress dialog example
+5.6k Golang : Skip or discard items of non-interest when iterating example
+9.6k Golang : Get currencies exchange rates example
+7.6k Golang : Sort lines of text example
+23.4k Golang : convert rune to integer value
+4.5k Javascript : Shuffle or randomize array example
+6.1k Web : How to see your website from different countries?
+4.2k Python : Convert(cast) string to bytes example
+14.7k Golang : Generate universally unique identifier(UUID) example
+5k Golang : Function as an argument type example
+8.4k Golang : Qt get screen resolution and display on center example
+5.2k Golang : Create new color from command line parameters