Grasshopper

algorithmic modeling for Rhino

Hello,

I'm exporting ViewCaptures from a GHPython script, and would like to check if a picture with the same name already exists so as not to overwrite anything.

I'm looking for something like "rs.IsFile()". If "picture" exists, it should try "picture_1", if not "picture_2" and so on:

path = "C:\Users\MyName\Desktop\MyFolder\"

filename = "picture"

if rs.IsFile(path+filename): newname = filename+"_1"

else: newname = filename

count = 0

while rs.IsFile(path+newname):

    newname = newname[:len(filename)+1]+str(count)
    count += 1

Views: 483

Replies to This Discussion

you can try os module for that

import os

os.path.isfile(full file path)

Ah, easy!

Thanks.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service