Create a Folder in the Current dwg folder

Anyone have a simple dyn file to create a folder in the dwgs current folder?
Any help would be appreciated.

CreateSubmittalDwgs.dyn (14.4 KB)

This dyn works if there are no file names that match files in current dwg folder. If it encounters a file that exists, instead of skipping it, it just stops… If I could make this dyn file just skip existing files and folders and not error and stop when it encounters one, then this would work for us.

A little Python should do the trick. This will throw an exception if the folder already exists.

import os

def create_folder(path, folderName):
    if path is None or folderName is None:
        return
    fullPath = path + "\\" + folderName
    os.mkdir(fullPath)
    return "Directory created successfully at " + fullPath 
OUT = create_folder(IN[0], IN[1])
2 Likes

The Reply is much appreciated, but… I do not know python… does that replace everything in the Python Script that comes up when you insert that “Python Script block” and select edit? Or does it get pasted at the end?

I assume I at least have to leave:
# Load the Python Standard and DesignScript Libraries
import sys
import clr

There are core nodes to create and manage files and directories. A folder is just a directory.

6 Likes


@Nick_Boyts
Thank you , this worked great…

Very cool Nick, I didn’t realize that node would create a new directory if it doesn’t exist.

I know you don’t need this anymore, but to answer the question, you would copy and paste everything verbatim into the Python Script node.

1 Like

Thanks Nick! I might use this for exporting excel files to a new child directory of the current working drawing.

1 Like

This may be an alternate solution.

CopyFolderToCurrent_dwgs_Folder_Python.dyn (12.9 KB)