mirror of
https://github.com/JaCoB1123/dupe-finder.git
synced 2025-07-03 09:08:54 +02:00
Move funcs to other file
This commit is contained in:
39
file.go
Normal file
39
file.go
Normal file
@ -0,0 +1,39 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func remove(path string) {
|
||||
if !*force {
|
||||
return
|
||||
}
|
||||
|
||||
if *moveToFolder == "" {
|
||||
os.Remove(path)
|
||||
return
|
||||
}
|
||||
|
||||
moveButDontOvewrite(path, *moveToFolder)
|
||||
}
|
||||
|
||||
func moveButDontOvewrite(path string, targetPath string) {
|
||||
num := 0
|
||||
|
||||
filename := filepath.Base(path)
|
||||
|
||||
target := filepath.Join(targetPath, filename)
|
||||
|
||||
for {
|
||||
_, err := os.Stat(target)
|
||||
if os.IsNotExist(err) {
|
||||
os.Rename(path, target)
|
||||
return
|
||||
}
|
||||
|
||||
target = filepath.Join(targetPath, filename+"."+strconv.Itoa(num))
|
||||
num++
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user