Reputation: 128
i want to search after a code which search a file called hw.exe on my hdd.
i have found this following code:
set files [glob hw.exe]
set sofar -1
foreach f $files {
set size [file size $f]
if {$size > $sofar} {
set sofar $size
set name $f
}
}
puts "Biggest files is $name at $sofar bytes"
Has anybody one idea to correct this? Or is there a function?
Upvotes: 0
Views: 64
Reputation: 137557
The fileutil package in Tcllib has the capability that you're looking for, provided you write the right filter. Finding the largest file can then be done over the returned list, which ought to be far smaller than the list of all files on the drive!
package require fileutil
proc filter {name} {
return [string match hw.exe $name]
}
set hwlist [fileutil::find C:/ filter]
set sofar -1
set name ""
foreach f $hwlist {
set size [file size $f]
if {$size > $sofar} {
set name $f
set sofar $size
}
}
puts "Found $name of size $sofar"
Upvotes: 2