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
+9.3k Golang : Proper way to test CIDR membership of an IP 4 or 6 address example
+18k Golang : How to count the number of repeated characters in a string?
+7.8k Golang : Qt Yes No and Quit message box example
+4.6k Facebook : How to force facebook to scrape latest URL link data?
+6.5k Golang : Auto-generate reply email with text/template package
+5.6k Golang : Fibonacci number generator examples
+3.6k Golang : Check if a word is countable or not
+8.7k Golang : Select region of interest with mouse click and crop from image
+7.5k Golang : What is the default port number for connecting to MySQL/MariaDB database ?
+4.4k Golang : Use NLP to get sentences for each paragraph example
+45.7k Golang : Disable security check for HTTPS(SSL) with bad or expired certificate
+6.1k Setting $GOPATH environment variable for Unix/Linux and Windows