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.8k Golang : Pat multiplexer routing example
+2.8k Java : Random alphabets, alpha-numeric or numbers only string generator
+11.1k Golang : calculate elapsed run time
+20.6k Golang : How to reverse slice or array elements order
+13k Golang : ROT47 (Caesar cipher by 47 characters) example
+16.1k Golang : How to remove certain lines from a file
+8.7k Golang : Sort and reverse sort a slice of integers
+4.8k Golang : Use NLP to get sentences for each paragraph example
+20.2k SSL : How to check if current certificate is sha1 or sha2
+12.6k Golang : Gin framework accept query string by post request example
+6.4k Golang : Get YouTube playlist
+3.8k Nginx and PageSpeed build from source CentOS example