Fix more windows edge cases
This commit is contained in:
parent
7a78105b75
commit
85feb33730
15
main.go
15
main.go
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue