Jesse001
Jesse001

Reputation: 924

Setting auto-sequencing file names in netlogo

I am exporting a results table from netlogo to .csv and would like to have it change the file name in sequence each time.

For example the first run on of the session would be file_1.csv the second file_2.csv etc.

I see how to do this manually, but is there a way to automate it? I'm guessing it has something to do with

if file-exists? = TRUE 
   [file-open "file_?1.csv" 
      ask patches [ "say stuff"]
   file-close]

but I'm missing something. any advice is always appreciated!

Upvotes: 3

Views: 172

Answers (1)

Arthur Hjorth
Arthur Hjorth

Reputation: 889

file-exists? takes a string as an argument. So you could do something like this:

let counter 0
let saved? false
while not saved? [
  let filename (word "file_" counter ".csv")
  if not file-exists? filename [
    file-open filename
    file-print "stuff"
    file-close
    set saved? true
  ]
  set counter counter + 1
]

Upvotes: 2

Related Questions