yoink-go initial commit
This commit is contained in:
31
comic/cleanup.go
Normal file
31
comic/cleanup.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package comic
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (c *Comic) Cleanup() error {
|
||||
filepath.Walk(
|
||||
filepath.Join(c.LibraryPath, c.Title),
|
||||
func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if info.IsDir() {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, ext := range []string{".jpg", ".jpeg", ".png"} {
|
||||
edited := strings.Replace(info.Name(), c.Title, "", 1)
|
||||
edited = strings.Trim(edited, " ")
|
||||
|
||||
if !strings.HasPrefix(strings.ToLower(edited), "001") && strings.HasSuffix(info.Name(), ext) {
|
||||
return os.Remove(path)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user