I'm trying to create a folder on Windows but keep getting an error and do not understand why.
The code snippet:
reader := bufio.NewReader(os.Stdin)
fmt.Print("Hostname: ")
hostname, _ := reader.ReadString('\n')
now := time.Now().Format("20060102150405")
var folderName string = fmt.Sprintf("%s_%s", now, hostname)
err := os.Mkdir(folderName, os.ModePerm)
if err != nil {
log.Fatal(err)
}
The error (translated from Dutch):
2022/06/10 13:37:13 mkdir 20220610133713_TEST
: The syntax of the file name, folder name or volume name is incorrect.
exit status 1
I tried using the full path with \\ and a relative path .\ or .\\
I got around the error with the code below, but that's not the way to go... ;)
cmd := exec.Command("cmd.exe", "/C", fmt.Sprintf("mkdir %s", folderName))
err := cmd.Run()
The issues is probably obvious but I fail to see the reason. Maybe something Windows specific?
Anyway thanks for having a look.