Re: Recursive proc/check file size



Cameron Laird wrote:
In article <HdydnXOmic_KJ7LVnZ2dnUVZ8j6dnZ2d@xxxxxx>,
Neil Madden <nem@xxxxxxxxxxxxx> wrote:
.
.
.
If you only need to check the previous size, then you don't need a list -- just an extra parameter. Also, if you combine the last two lines then you can use the event loop so that (a) you don't keep consuming stack space which each recursive call, and (b) you can potentially do other tasks while this loop is running:

proc checksize {myfile {prevsize 0}} {
set filesize [file size $myfile]
puts $filesize
if {$filesize > 0 && $filesize == $prevsize} {
puts "all done"
} else {
after 1000 [list checksize $myfile $filesize]
}
}
...
checksize $myfile
vwait forever ;# not needed if Tk is running

-- Neil

Excellent advice.

I'm a tiny bit concerned that filesize on the first invocation
might be zero--do you see the difficulty I do?

Isn't this what the $filesize > 0 guard is for? (I took that directly from Kevin's original code).

-- Neil
.



Relevant Pages

  • Re: Recursive proc/check file size
    ... set filesize [file size $myfile] ... puts "all done" ... acts just the same), but it kind of makes sense (besides, we don't want to use list commands to strings, do we? ...
    (comp.lang.tcl)
  • Re: Recursive proc/check file size
    ... you can use the event loop so that you don't keep consuming stack ... set filesize [file size $myfile] ... puts "all done" ...
    (comp.lang.tcl)
  • Re: Recursive proc/check file size
    ... you can use the event loop so that you don't keep consuming stack ... set filesize [file size $myfile] ... puts "all done" ...
    (comp.lang.tcl)
  • Re: Recursive proc/check file size
    ... proc checksize { ... set filesize [file size $myfile] ... puts "all done" ...
    (comp.lang.tcl)