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
+12.8k Golang : Handle or parse date string with Z suffix(RFC3339) example
+8.1k Your page has meta tags in the body instead of the head
+13k Golang : Linear algebra and matrix calculation example
+13.2k Golang : Get user input until a command or receive a word to stop
+15.1k Golang : invalid character ',' looking for beginning of value
+37.1k Upload multiple files with Go
+4.6k Golang : PGX CopyFrom to insert rows into Postgres database
+5.9k Golang : Scan forex opportunities by Bollinger bands
+7.9k Golang : HTTP Server Example
+8.2k PHP : How to parse ElasticSearch JSON ?
+7.4k Gogland : Where to put source code files in package directory for rookie
+8.5k Golang : Random integer with rand.Seed() within a given range