initial commit of bin scripts into git
This commit is contained in:
59
delete_duplicate_photos_in_storage
Executable file
59
delete_duplicate_photos_in_storage
Executable file
@@ -0,0 +1,59 @@
|
||||
#!/bin/sh
|
||||
# \
|
||||
exec tclsh "$0" ${1+"$@"}
|
||||
|
||||
proc FindFiles {dir} {
|
||||
global argv0 files
|
||||
|
||||
if { [catch {glob $dir/* $dir/.*} ents] } { return }
|
||||
foreach ent $ents {
|
||||
if { [file tail $ent] == "." || [file tail $ent] == ".." } { continue }
|
||||
if { [file isdirectory $ent] } {
|
||||
FindFiles $ent
|
||||
} else {
|
||||
lappend files $ent
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if { $argc != 1 } {
|
||||
puts "Usage: $argv0 <dir>"
|
||||
exit 1
|
||||
}
|
||||
set files ""
|
||||
FindFiles [lindex $argv 0]
|
||||
set orig_list $files
|
||||
foreach file "$files" {
|
||||
if { [catch { file size $file } size($file)] } {
|
||||
puts stderr "$file does not exist (sym link to nothing?)"
|
||||
}
|
||||
if { $size($file) == 0 } { puts "$file is zero bytes!" }
|
||||
}
|
||||
|
||||
set cnt 0
|
||||
foreach file "$orig_list" {
|
||||
if { $cnt == 75 } {
|
||||
puts -nonewline "."
|
||||
flush stdout
|
||||
set cnt 0
|
||||
}
|
||||
incr cnt
|
||||
foreach tst_f $files {
|
||||
if { $size($tst_f) != $size($file) } { continue }
|
||||
if { $tst_f == $file || $size($file) == 0 } { continue }
|
||||
catch {eval exec diff -s $file $tst_f} output
|
||||
if { [regexp "identical" $output m] == 1 } {
|
||||
puts stderr "$file == $tst_f (size: $size($file))"
|
||||
if { [regexp {20\d\d\d\d\d\d[_-]} $file] } {
|
||||
puts "based on name, I would keep file: $file and delete: $tst_f"
|
||||
exec rm $tst_f
|
||||
} elseif { [regexp {20\d\d\d\d\d\d[_-]} $tst_f] } {
|
||||
puts "based on name, I would keep tst_f: $tst_f and delete: $file"
|
||||
exec rm $file
|
||||
}
|
||||
}
|
||||
}
|
||||
# only check remainder of files (e.g. lindex 0 was just compared)
|
||||
set files [lrange $files 1 end]
|
||||
}
|
||||
Reference in New Issue
Block a user