File io NetLogo-检查文件是否已更改
检查文件是否已更改并仅打印新数据的有效方法是什么 最初,我倾向于使用readline方法来比较行数,但这似乎效率很低 我最初的问题是,是否有办法从Netlogo检查文件大小或时间戳。答案是“不”。然而,Charles Staelin非常友好地将get date ms方法添加到pathdir扩展中。因此,现在可以使用File io NetLogo-检查文件是否已更改,file-io,netlogo,File Io,Netlogo,检查文件是否已更改并仅打印新数据的有效方法是什么 最初,我倾向于使用readline方法来比较行数,但这似乎效率很低 我最初的问题是,是否有办法从Netlogo检查文件大小或时间戳。答案是“不”。然而,Charles Staelin非常友好地将get date ms方法添加到pathdir扩展中。因此,现在可以使用set currenttimestamp pathdir:get date ms“somefile.nlist”检查文件更改(根据时间戳) 如果currenttimestamp!=文件
set currenttimestamp pathdir:get date ms“somefile.nlist”检查文件更改(根据时间戳)
如果currenttimestamp!=文件时间戳
使用添加的方法:
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最近将其添加到他的
pathdir
扩展中,该扩展为NetLogo添加了各种面向文件和路径的原语。看见扩展名列在