Copy a Folder full of Files and Folders to the Current dwg folder

CreateSubmittalDwgs.dyn (14.4 KB)
I have this dyn that will do exactly want we need, except instead of skipping a file or folder if it exists, it just errors out and stops. Any suggestion to fix it would be appreciated.

You’d have to get creative and figure out which files and subfolders already exist in the destination folder and filter those out before copying. This can probably be accomplished with OOTB nodes like FileSystem.GetDirectoryContents, FileSystem.FileExists, FileSystem.DirectoryExists, etc. although it would probably require a bit of gymnastics. I think using Python might be a little more elegant.

Try this. The IN[0] input would be the path to the source directory, and IN[1] is the path to the destination directory. This will copy over files and folders from the source to the destination, but only if they do not already exist in the destination.

import os, shutil

# Inputs
src_dir = IN[0]
dest_dir = IN[1]

for src_sub_dir, dirs, files in os.walk(src_dir):
    
    # Create subfolders if they do not exist
    dst_sub_dir = src_sub_dir.replace(src_dir, dest_dir, 1)
    if not os.path.exists(dst_sub_dir):
        os.makedirs(dst_sub_dir)
    
    # Copy each file
    for file_ in files:
        src_file = os.path.join(src_sub_dir, file_)
        dst_file = os.path.join(dst_sub_dir, file_)
        
        # Skip if file already exists
        if os.path.exists(dst_file):
            continue
        shutil.copy(src_file, dst_sub_dir)
3 Likes

Python is awesome…
Thank you - much appreciated.

1 Like

Final dyn file:
CopyFolderToCurrent_dwgs_Folder_Python.dyn (12.9 KB)