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.4k Golang : Break string into a slice of characters example
+15.6k Golang : Get input from keyboard
+12.8k How to automatically restart your crashed Golang server
+7.1k Golang : Auto-generate reply email with text/template package
+12.8k Golang : convert(cast) string to float value
+10.3k Golang : How to flush a channel before the end of program?
+8.6k Golang : Eroding and dilating image with OpenCV example
+7.3k Golang : How to check if input string is a word?
+8.2k Golang : How to control fmt or log print format?
+10k Golang : Characters limiter example
+17.6k Golang : Populate dropdown with html/template example
+5.6k Golang : When to use make or new?