Fix all the things
This commit is contained in:
parent
736da4c326
commit
a8161270fc
|
@ -1,2 +1,5 @@
|
|||
.idea/
|
||||
qrcode-bulk
|
||||
|
||||
*.txt
|
||||
qrcodes/
|
||||
|
|
12
main.go
12
main.go
|
@ -12,7 +12,7 @@ import (
|
|||
)
|
||||
|
||||
func handleErr(format string, args ...interface{}) {
|
||||
fmt.Printf(format, args)
|
||||
fmt.Printf(format, args...)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ func main() {
|
|||
if err != nil {
|
||||
handleErr("Could not get current dir: %s", err)
|
||||
}
|
||||
if workingDir == "" {
|
||||
if workingDir == "" || workingDir == "\n" || workingDir == "\n\r" {
|
||||
workingDir = cwd
|
||||
}
|
||||
|
||||
|
@ -44,12 +44,12 @@ func main() {
|
|||
}
|
||||
|
||||
// 2. Get Files
|
||||
files, err := filepath.Glob(path.Join(workingDir, "*.txt"))
|
||||
files, err := filepath.Glob(workingDir + "/*.txt")
|
||||
if err != nil {
|
||||
handleErr("Could not get files: %s", err)
|
||||
}
|
||||
|
||||
fmt.Printf("Generating %d QR Codes...\n\r", len(files))
|
||||
fmt.Printf("Generating %d QR Codes from files in %s...\n\r", len(files), workingDir)
|
||||
|
||||
for _, file := range files {
|
||||
f, err := os.Open(file)
|
||||
|
@ -59,12 +59,12 @@ func main() {
|
|||
if !strings.HasSuffix(f.Name(), ".txt") {
|
||||
continue
|
||||
}
|
||||
content, err := ioutil.ReadFile(path.Join(workingDir, f.Name()))
|
||||
content, err := ioutil.ReadFile(file)
|
||||
if err != nil {
|
||||
handleErr("Could not open file '%s': %s", f.Name(), err)
|
||||
}
|
||||
// 3. Generate QR-Codes and save
|
||||
err = qrcode.WriteFile(string(content), qrcode.High, 1024, path.Join(outPath, strings.TrimSuffix(f.Name(), path.Ext(file))))
|
||||
err = qrcode.WriteFile(string(content), qrcode.Low, 2048, path.Join(outPath, strings.TrimSuffix(path.Base(f.Name()), path.Ext(file)))+".png")
|
||||
if err != nil {
|
||||
handleErr("Could not create qr code for file '%s': %s", f.Name(), err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue