Skip to content

Instantly share code, notes, and snippets.

@hygull
Created December 10, 2016 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hygull/12c8d4918fed3ef0393fa60a0069ea9e to your computer and use it in GitHub Desktop.
Save hygull/12c8d4918fed3ef0393fa60a0069ea9e to your computer and use it in GitHub Desktop.
plateform independent directory creation created by hygull - https://repl.it/Emay/0
/*
{
"cretaed_after" : "Sat Dec 10 12:01:49 IST 2016"
"aim_of_program" : "To create a new directory in current working directory(On MAC/UNIX/Windows)"
"coded_by" : "Rishikesh Agrawani"
}
*/
package main
import (
"fmt"
"os"
"path/filepath"
)
func main() {
//In windows --> .\GolangDir
//In Unix/MAC --> ./GolangDir
//Lets do platform independent implementation for making directory in current working directory
if _, err := os.Stat("." + string(filepath.Separator) + "GolangDir"); os.IsNotExist(err) {
os.Mkdir("."+string(filepath.Separator)+"GolangDir", 0777)
fmt.Println("Directory created.")
} else {
fmt.Println("Directory exists.")
}
}
/*FIRST RUN:-
Directory created.
SECOND RUN:-
Directory exists.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment