0
什麼是有效的方法來檢查文件是否發生了變化,並只打印新的數據?NetLogo - 檢查文件是否發生了變化
最初,我傾向於比較行數的readline方法,但這看起來效率很低。
我最初的疑問是如果有辦法從Netlogo檢查文件大小或時間戳。答案是'不'。然而,Charles Staelin很友好地將get-date-ms方法添加到pathdir擴展中。所以,現在的文件更改(按時間戳)可以檢查與set currenttimestamp pathdir:get-date-ms "somefile.nlist" if currenttimestamp != filetimestamp
使用添加方法:
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