NetLogo - 检查文件是否已更改

时间:2012-09-25 22:14:31

标签: file-io netlogo

检查文件是否已更改且仅打印新数据的有效方法是什么?

最初,我倾向于使用比较线方法来比较线数,但这看起来非常低效。

我的初步查询是否有办法从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

1 个答案:

答案 0 :(得分:0)

Charles Staelin最近将此添加到他的pathdir扩展中,该扩展为NetLogo添加了各种各样的文件和路径导向基元。见http://groups.yahoo.com/group/netlogo-users/message/15301。该扩展程序列在https://github.com/NetLogo/NetLogo/wiki/Extensions