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
+12.8k Golang : Sort and reverse sort a slice of bytes
+6.1k Golang : How to verify input is rune?
+12.9k Swift : Convert (cast) Int or int32 value to CGFloat
+13.3k Golang : Convert(cast) int to int64
+16.2k Golang : Generate universally unique identifier(UUID) example
+6.1k Golang : Extract unicode string from another unicode string example
+20k Golang : Accept input from user with fmt.Scanf skipped white spaces and how to fix it
+11.7k Golang : Surveillance with web camera and OpenCV
+6.3k Golang & Javascript : How to save cropped image to file on server
+5.6k Golang : If else example and common mistake
+11.5k Golang : Post data with url.Values{}
+5.8k Get website traffic ranking with Similar Web or Alexa