Merge Directories in Python on Mac - VicPhanDevOps/mac GitHub Wiki

• Type python3 and press the return key to get into the Python interactive shell.
image

• Type import os, shutil and press the return key to import the os and shutil modules.
image

• Type from pathlib import Path and press the return key to import the Path object from the pathlib module.
image

• Type < source directory > = Path(“< source directory >”) and press the return key to set the source directory.
image

• Type < destination directory > = Path(“< destination directory >”) and press the return key to set the destination directory.
image

• Type os.listdir(< source directory >) and press the return key to list the contents of the source directory.
image

• Type os.listdir(< destination directory >) and press the return key to list the contents of the destination directory.
image

• Type shutil.copytree(< source directory >, < destination directory >, dirs_exist_ok = True) and press the return key to merge the files from the source directory into the destination directory.
image

• Type os.listdir(dir2) and press the return key to list the contents of the destination directory and you will see it now contains the files from the source directory and the files that were there before the merge.
image

• Type exit() or quit() and press the return key to exit the Python interactive shell and return to the UNIX-like shell.
image

⚠️ **GitHub.com Fallback** ⚠️