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
+5k Golang : Experimenting with the Rejang script
+14.9k Golang : convert string or integer to big.Int type
+12.5k Golang : Human readable time elapsed format such as 5 days ago
+8k Golang : Serving HTTP and Websocket from different ports in a program example
+6.3k Golang : Dealing with struct's private part
+18.3k Golang : Check if os.Stdin input data is piped or from terminal
+5.5k Golang : How to determine if request or crawl is from Google robots
+28.4k Golang : How to verify uploaded file is image or allowed file types
+5.2k Golang : How to get capacity of a slice or array?
+6.7k Golang : Ways to recover memory during run time.
+5.5k Golang : Find the longest line of text example
+9.4k Golang : ISO8601 Duration Parser example