mirror of
https://github.com/fumiama/dupimage.git
synced 2026-06-12 22:40:21 +08:00
add ext match
This commit is contained in:
@@ -3,9 +3,11 @@ Detect duplicated images and gather each group into a unique subfolder.
|
|||||||
|
|
||||||
## usage
|
## usage
|
||||||
```powershell
|
```powershell
|
||||||
|
Usage: dupimage [-adht] ext1 ext2...
|
||||||
-a action sort
|
-a action sort
|
||||||
-d string
|
-d string
|
||||||
work directory (default "./")
|
work directory (default "./")
|
||||||
-t uint
|
-t uint
|
||||||
duplicate throttle, max is 64 (default 5)
|
duplicate throttle, max is 64 (default 5)
|
||||||
|
exts matching extensions
|
||||||
```
|
```
|
||||||
|
|||||||
28
main.go
28
main.go
@@ -7,6 +7,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
_ "image/gif"
|
_ "image/gif"
|
||||||
@@ -31,11 +32,23 @@ func main() {
|
|||||||
tht := flag.Uint("t", 5, "duplicate throttle, max is 64")
|
tht := flag.Uint("t", 5, "duplicate throttle, max is 64")
|
||||||
dir := flag.String("d", "./", "work directory")
|
dir := flag.String("d", "./", "work directory")
|
||||||
a := flag.Bool("a", false, "action sort")
|
a := flag.Bool("a", false, "action sort")
|
||||||
|
h := flag.Bool("h", false, "display help")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
if *h {
|
||||||
|
fmt.Println("Usage:", os.Args[0], "[-adht] ext1 ext2...")
|
||||||
|
flag.PrintDefaults()
|
||||||
|
fmt.Println(" exts\tmatching extensions")
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
throttle := *tht
|
throttle := *tht
|
||||||
if throttle > 64 {
|
if throttle > 64 {
|
||||||
panic("invalid throttle")
|
panic("invalid throttle")
|
||||||
}
|
}
|
||||||
|
exts := flag.Args()
|
||||||
|
for i, e := range exts {
|
||||||
|
exts[i] = strings.ToLower(e)
|
||||||
|
}
|
||||||
|
fmt.Println("match extension:", exts)
|
||||||
err := os.Chdir(*dir)
|
err := os.Chdir(*dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@@ -57,11 +70,20 @@ func main() {
|
|||||||
if to > len(imgs) {
|
if to > len(imgs) {
|
||||||
to = len(imgs)
|
to = len(imgs)
|
||||||
}
|
}
|
||||||
|
isextinlist := func(n string) bool {
|
||||||
|
for _, e := range exts {
|
||||||
|
if strings.HasSuffix(strings.ToLower(n), e) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
go func(from, to int) {
|
go func(from, to int) {
|
||||||
for i := from; i < to; i++ {
|
for i := from; i < to; i++ {
|
||||||
img := imgs[i]
|
img := imgs[i]
|
||||||
if !img.IsDir() {
|
n := img.Name()
|
||||||
f, err := os.Open(img.Name())
|
if !img.IsDir() && isextinlist(n) {
|
||||||
|
f, err := os.Open(n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -75,7 +97,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
chklst = append(chklst, imagecheck{
|
chklst = append(chklst, imagecheck{
|
||||||
name: img.Name(),
|
name: n,
|
||||||
dh: dh,
|
dh: dh,
|
||||||
})
|
})
|
||||||
fmt.Print("scan: ", len(chklst), " / ", len(imgs), "\r")
|
fmt.Print("scan: ", len(chklst), " / ", len(imgs), "\r")
|
||||||
|
|||||||
Reference in New Issue
Block a user