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
+17.1k Google Chrome : Your connection to website is encrypted with obsolete cryptography
+7.1k Golang : Accessing dataframe-go element by row, column and name example
+39.9k Golang : Convert to io.ReadSeeker type
+16.5k Golang : Gzip file example
+19k Golang : Delete item from slice based on index/key position
+14.7k Golang : Basic authentication with .htpasswd file
+7.2k Golang : Individual and total number of words counter example
+7.5k Golang : Error reading timestamp with GORM or SQL driver
+29.1k Golang : Record voice(audio) from microphone to .WAV file
+10k Golang : Random Rune generator
+12.9k Golang : How to calculate the distance between two coordinates using Haversine formula
+25.6k Golang : Convert IP address string to long ( unsigned 32-bit integer )