How I can delete external files?

I do need to save some csv files a few times into a directory and I am facing the situation in which some of the old files are no more required and unfortunately they are mixed with overwritten new ones.

It is there a way in Grasshopper to delete automatically this files for me?

You can use os.remove(filePath) from a Python scripting component.

1 Like

I do get this error:

Runtime error (UnboundNameException): name 'os' is not defined

Traceback:
  line 14, in script

My script looks like this:

import rhinoscriptsyntax as rs

filePath = x
os.remove(filePath)

P.S: How I can add a button trigger as input into the script?

Ah yes, sorry you need to import the os module. Here’s a quick example, where we also check if the file exists:


240223_DeleteFile_GHPython_00.gh (3.7 KB)

1 Like

Thank you. Now it is working.

1 Like