Copy folders with Python

one line to copy entire folders

18 Jul 2022

Having had issues copying large folders (100Gb+) with (Path)Finder, here is the code snippet I used to perform the task with Python (much faster too):

import shutil

shutil.copytree('/path/to/source/folder/on/network/Pictures', '/path/to/destination/folder', dirs_exist_ok=True)

dirs_exist_ok=True ensures files are overwritten when present, taking care of possible past file corruptions.

with printing progress:

from datetime import datetime
from shutil import copytree,copy2

def copy2_verbose(src, dst):
    print(f"{'%H:%M:%S')} copying: {src}")

copytree('/Volumes/Nisubz’s Public Folder/movies', '/Volumes/Videos/Movies', dirs_exist_ok=True, copy_function=copy2_verbose)