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
+10.2k Golang : How to display image file or expose CSS, JS files from localhost?
+5.8k Javascript : Put image into Chrome browser's console
+4k Swift : Convert string array to array example
+7.9k Golang : Detect number of faces or vehicles in a photo
+11.5k Golang : Simple word wrap or line breaking example
+16k Golang : Send email with attachment
+4.1k Fix yum-complete-transaction error
+3.3k Linux/MacOSX : How to symlink a file?
+7.7k Golang : Ordinal and Ordinalize a given number to the English ordinal numeral
+7.8k Golang : Check if user agent is a robot or crawler example
+4k Golang : Shortening import identifier
+4.6k Linux/Unix : Commands that you need to be careful about