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
+13.3k Golang : How to shuffle elements in array or slice?
+15.6k Golang : Capture stdout of a child process and act according to the result
+10.7k Golang : Gorilla web tool kit secure cookie example
+26k Golang : Convert integer to binary, octal, hexadecimal and back to integer
+13k Golang : Send email with attachment(RFC2822) using Gmail API example
+4.5k Clean up Visual Studio For Mac installation failed disk full problem
+5.5k Nginx : Password protect a directory/folder
+14.1k Golang : Get query string value on a POST request
+9.2k Golang : Convert file unix timestamp to UTC time example
+19.1k Golang : How to force compile or remove object files first before rebuild?
+17.2k Golang : Send email with attachment
+4.8k Fix fatal error: evacuation not done in time problem