Create folder with Grasshopper

Hello, at the old forum I’ve found a discussion about making folder with Grasshopper,

There is a .gh file which does the work, but it only creates the folder in the desktop.
What should I change in the C# code to create a folder in a custom place ?

150730_Create_new_directory_MT_csharp (1).gh (7.4 KB)

Thank you


you can do almost anything from Grasshopper. This question is about basic programming. The best resource can be found on Microsoft Developers page or on Stack Overflow.

Hope this helps

if (x == true){d = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);}
A = d;

Here is the C# code which creates the path,unfortunately i dont understand coding and i’m not sure what could I change

here it is:

 if (create)
    } (4.7 KB)


Thank you :slight_smile:

Hey guys!

I find this topic interesting, I have additional question. If C# can create folder. is there a way to open a folder using code in GH?

sure: (5.2 KB)

if (open)
    System.Diagnostics.Process.Start("explorer.exe", folder);

Nice, just what I was looking for.

Is there a way to add an output that changes from the false (default) to true once the folder is created successfully? I am trying to trigger a copy function (using a different component) that expects the folder to exist already, so it has to be triggered AFTER the create folder has done its thing.

Really coming to the limitations of what you can do with GH components (not code) in terms of timing these things…

Creating files and folders is not an async operation (of course unless you invoke them async). This means, once a new file/folder had been created it should be pretty straightforward to add any bool to the output, since GH only continues until the folder had been created . So assuming you created a new Output Parameter called „A“ you can assign a true to within the conditional branch and for any other a false.

You can also track behavior of files and directories by using the FileWatcher class and subscribing to its events. But I can only repeat the following on and on. Prevent creating async behavior from scripts and Gh definitions, and if you do keep it within the scope of execution. Scripts are meant to be linear, Gh definitions as well.

Hello ,
plz I need a help the create folder is working but suddenly it stop for no reason , so why many times it crush???or if it is working the other component that create the new destination stop and crush , as attached in the picture

plz help

Windows paths use backslashes like \ for paths not forward slashes /. And only one is used not 2 like you have there.

You can see how a proper path is written if you go to a folder in Explorer and then click in the Path bar you will see the path:

I think you got it mixed up with Web URLs that use 2 forward slashes “http://www…”.

Thank you so much for your fast reply I will try it
Best regards

dear still not working and tell me that could not find part of the path!! whats should I do and srry for bothering you

if the folder is already existed, how can we overwrite it again to replace its contained data

Normally it will overwrite anything without warning.

I noticed that your paths contain spaces, which means you might have to handle it differently in Python. I don’t know much Python, but usually you have to escape the spaces or put " " around the path if it contains spaces. Otherwise it will just look for the part till the first space, which is E:/Save in your case.

Here is a good article explaining how to efficiently use paths in Python:

Is it possible to create a folder structure on a google drive through a script in a grasshopper?

Yes this is possible, but it won’t be as simple as creating it within one line. Google Drive is a Web/Cloud service, so you have to trigger this over the Google API. I don’t know how to do this in detail …

You should be able to integrate your google drive as a folder/drive just like you can do with dropbox etc. Then you should be able to just access it via its folder path.

I found a simple solution) the folder structure that is on the hard drive, I dragged it to google drive