0

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

最初,我倾向于比较行数的 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
4

1 回答 1

0

Charles Staelin 最近将此添加到他的pathdir扩展中,它为 NetLogo 添加了各种面向文件和路径的原语。请参阅http://groups.yahoo.com/group/netlogo-users/message/15301。扩展列在https://github.com/NetLogo/NetLogo/wiki/Extensions

于 2012-10-02T17:56:00.287 回答