Archived
1
0

Adds removal of empty category directories

This commit is contained in:
Jip J. Dekker 2016-10-02 02:42:48 +02:00
parent b2f45d6add
commit 6d32fe2c38
2 changed files with 26 additions and 0 deletions

View File

@ -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)

View File

@ -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
}