You can fully Tcl-ify the find-type functionality with something like the recursive procedure below.
You can then walk through the found files and delete them.
Or, you could just have the finder delete them whenever it finds one – your choice.
namespace eval findFiles {
}
proc findFiles::recursiveFindSmallFiles { filePath foundArrayName maxFileBytes } {
upvar $foundArrayName foundArray
set files [glob -nocomplain “$filePath/*”]
foreach f $files {
if { [file isdirectory $f] } {
findFiles::recursiveFindSmallFiles $f foundArray $maxFileBytes
} else {
set fs [file size $f]
if { $fs <= $maxFileBytes } {
set i $foundArray(numFound)
set foundArray($i,filePath) $f
set foundArray($i,fileSize) $fs
incr foundArray(numFound)
}
}
}
}
proc findFiles::findSmallFiles { dir foundArrayName maxFileBytes } {
upvar $foundArrayName foundArray
catch {unset foundArray}
set foundArray(numFound) 0
findFiles::getSmallFiles $dir foundArray $maxFileBytes
}
#
# Usage example
#
findFiles::findSmallFiles foundArray 0
for { set i 0 } { $i < $foundArray(numFound) } { incr i } {
# use file delete here if you want to delete the found files
puts "size= $foundArray($i,fileSize), path= $foundArray($i,filePath)"
}
Jeff Dinsmore
Chesapeake Regional Healthcare