Re: Recursive proc/check file size
- From: Neil Madden <nem@xxxxxxxxxxxxx>
- Date: Sun, 18 May 2008 06:10:45 +0100
Kevin Walzer wrote:
I'm trying to recursively run a procedure to check a file size and then end when the file size stops increasing. Here is my code:[...]
proc checksize {myfile} {
set filesize [file size $myfile]
lappend sizelist $filesize
puts $sizelist
if {$filesize > 0 && [lindex $sizelist end] == [lindex $sizelist end-1]} {
puts "all done"
}
after 1000
checksize $myfile
}
It appears that a single-item list is being returned each time, and so the comparison I am looking for (comparing the last item of the list with the next to last item, to make sure that the file size has stopped increasing) never gets run. Can anyone show me how to structure the procedure so that each iteration of the procedure adds to the list, rather than replacing it?
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
.
- Follow-Ups:
- Re: Recursive proc/check file size
- From: Cameron Laird
- Re: Recursive proc/check file size
- From: Ralf Fassel
- Re: Recursive proc/check file size
- From: Kaitzschu
- Re: Recursive proc/check file size
- From: Cameron Laird
- Re: Recursive proc/check file size
- References:
- Recursive proc/check file size
- From: Kevin Walzer
- Recursive proc/check file size
- Prev by Date: Re: Recursive proc/check file size
- Next by Date: Re: How to get path?
- Previous by thread: Re: Recursive proc/check file size
- Next by thread: Re: Recursive proc/check file size
- Index(es):
Relevant Pages
|