Added more stuff
This commit is contained in:
43
tasks/clean-mov-files.go
Normal file
43
tasks/clean-mov-files.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package tasks
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"varia-go/shared"
|
||||
)
|
||||
|
||||
type CleanMovFilesTask struct{}
|
||||
|
||||
func (t *CleanMovFilesTask) Run(folderPath string) error {
|
||||
return filepath.Walk(folderPath, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Check if the file has a .mov extension
|
||||
if filepath.Ext(info.Name()) == ".mov" {
|
||||
baseName := shared.FileNameWithoutExt(info.Name())
|
||||
heicPath := filepath.Join(filepath.Dir(path), baseName+".heic")
|
||||
jpgPath := filepath.Join(filepath.Dir(path), baseName+".jpg")
|
||||
|
||||
// Check if corresponding .heic or .jpg file exists
|
||||
heicExists, err := shared.FileExists(heicPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
jpgExists, err := shared.FileExists(jpgPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println(baseName)
|
||||
if heicExists || jpgExists {
|
||||
fmt.Printf("Sending to Recycle Bin: %s\n", path)
|
||||
if err := shared.MoveToTrash(path); err != nil {
|
||||
return fmt.Errorf("failed to move to Recycle Bin: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user