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
+4.5k JavaScript : Rounding number to decimal formats to display currency
+4.6k JavaScript: Add marker function on Google Map
+20k Golang : How to get struct tag and use field name to retrieve data?
+13.3k Golang : Get constant name from value
+4.9k Python : Convert(cast) bytes to string example
+9.4k Golang : Extract or copy items from map based on value
+13.3k Golang : error parsing regexp: invalid or unsupported Perl syntax
+7.3k Linux : How to fix Brother HL-1110 printing blank page problem
+16.3k Golang : Send email and SMTP configuration example
+24.4k Golang : Time slice or date sort and reverse sort example
+5.3k Golang : Reclaim memory occupied by make() example
+6k Golang : Build new URL for named or registered route with Gorilla webtoolkit example