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
+7.1k Prevent Write failed: Broken pipe problem during ssh session with screen command
+15.4k CodeIgniter/PHP : Create directory if does not exist example
+25.4k PHP : Convert(cast) string to bigInt
+12.5k Golang : Tutorial on loading GOB and PEM files
+12.9k Golang : Google Drive API upload and rename example
+11.7k Android Studio : Password input and reveal password example
+4.2k Golang *File points to a file or directory ?
+11k Golang : Get month name from date example
+11.4k Golang : HTTP response JSON encoded data
+9.3k Golang : Meaning of omitempty in struct's field tag
+10.5k Golang : Convert decimal number(integer) to IPv4 address
+19.9k Golang : GORM create record or insert new record into database example