Adds removal of empty category directories
This commit is contained in:
parent
b2f45d6add
commit
6d32fe2c38
@ -35,6 +35,17 @@ func Clean(path string, opts *settings.Settings) {
|
||||
helpers.CleanFile(scores[i].OutputPath)
|
||||
}
|
||||
|
||||
// Remove empty category directories
|
||||
if !opts.FlatOutputDir {
|
||||
cat := scoreCategories(&scores)
|
||||
for i := range cat {
|
||||
dir := filepath.Join(opts.OutputDir, cat[i])
|
||||
if t, err := helpers.EmptyDir(dir); t && err == nil {
|
||||
helpers.CleanFile(dir)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove LaTeX resources
|
||||
texPath := filepath.Join(opts.OutputDir, opts.Name+".tex")
|
||||
helpers.CleanFile(texPath)
|
||||
|
@ -16,6 +16,7 @@ package helpers
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
@ -112,3 +113,17 @@ func CleanFile(path string) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func EmptyDir(name string) (bool, error) {
|
||||
f, err := os.Open(name)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
_, err = f.Readdirnames(1) // Or f.Readdir(1)
|
||||
if err == io.EOF {
|
||||
return true, nil
|
||||
}
|
||||
return false, err // Either not empty or error, suits both cases
|
||||
}
|
||||
|
Reference in New Issue
Block a user