Fix more windows edge cases

This commit is contained in:
kolaente 2020-09-16 20:44:10 +02:00
parent 7a78105b75
commit 85feb33730
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 5 additions and 10 deletions

15
main.go
View File

@ -9,7 +9,6 @@ import (
"os"
"path"
"path/filepath"
"runtime"
"strings"
)
@ -40,22 +39,17 @@ func main() {
if err != nil {
handleErr("Could not get current dir: %s", err)
}
if workingDir == "" || workingDir == "\n" || workingDir == "\n\r" {
if workingDir == "" || workingDir == "\n" || workingDir == "\n\r" || workingDir == "\r\n" {
workingDir = cwd
}
outPath := filepath.Dir(path.Join(workingDir, "qrcodes"))
fmt.Printf("Creating output folder %s...\r\n", outPath)
outPath := path.Join(workingDir, "qrcodes")
if err := os.MkdirAll(outPath, os.ModePerm); err != nil {
handleErr("Could not create output folder: %s", err)
}
// 2. Get Files
glob := workingDir + "/*.txt"
if runtime.GOOS == "windows" {
glob = workingDir + "\\*.txt"
}
files, err := filepath.Glob(glob)
files, err := filepath.Glob(path.Join(workingDir, "/*.txt"))
if err != nil {
handleErr("Could not get files: %s", err)
}
@ -76,7 +70,8 @@ func main() {
handleErr("Could not open file '%s': %s", f.Name(), err)
}
// 3. Generate QR-Codes and save
err = qrcode.WriteFile(string(content), qrcode.Low, 2048, path.Join(outPath, strings.TrimSuffix(path.Base(f.Name()), path.Ext(file)))+".png")
outfile := path.Join(outPath, strings.TrimSuffix(path.Base(filepath.ToSlash(f.Name())), path.Ext(file))) + ".png"
err = qrcode.WriteFile(string(content), qrcode.Low, 2048, outfile)
if err != nil {
handleErr("Could not create qr code for file '%s': %s", f.Name(), err)
}