What is an efficient method to check if a file has changed and only print the new data?
Originally, I leaned towards a readline approach comparing line counts but that seemed very inefficient.
My initial query was if there was a way to check file size or time stamp from Netlogo. The answer was ‘no’. However, Charles Staelin was kind enough to add the get-date-ms method to the pathdir extension. So, now the file changes (as per time stamp) can be checked for with set currenttimestamp pathdir:get-date-ms "somefile.nlist"
if currenttimestamp != filetimestamp
Using the added method:
to checkfile
ifelse checktick mod 19 = 0
[set currenttimestamp pathdir:get-date-ms "somefile.nlist"
if currenttimestamp != filetimestamp
[file-open "somefile.nlist"
let thiscount 0
while [not file-at-end?][
set in1 file-read-line
set global-in1 in1
set thiscount thiscount + 1
if thiscount > global-filelength AND (not file-at-end?)[ ;it seems that this not-at-file-end is redundant - why not?
print in1
set global-filelength thiscount
set hasfilechanged true
]
]
file-close
set filetimestamp currenttimestamp
set checktick checktick + 1
]
]
[ set checktick checktick + 1]
end
Charles Staelin has recently added this to his
pathdirextension, which adds an assortment of file and path oriented primitives to NetLogo. see http://groups.yahoo.com/group/netlogo-users/message/15301 . The extension is listed at https://github.com/NetLogo/NetLogo/wiki/Extensions