shutil.copy2() vs shutil.copytree()
shutil.copy2() and shutil.copytree() are both Python Shutil Module APIs, and choosing between them is a common point of confusion. This page compares their syntax, parameters, return values, and typical use cases so you can pick the right one. shutil.copy2(): Like copy() but also preserves metadata (timestamps, permissions). Its syntax is shutil.copy2(src, dst, *, follow_symlinks=True), and it returns destination path string shutil.copytree(): Recursively copies an entire directory tree. Its syntax is shutil.copytree(src, dst, symlinks=False, ignore=None, copy_function=copy2, dirs_exist_ok=False), and it returns destination path string Example of shutil.copy2(): shutil.copy2("source.txt", "backup.txt"). Example of shutil.copytree(): shutil.copytree("project/", "backup_project/"). Read the full references for shutil.copy2() and shutil.copytree() to see parameters, edge cases, and example code side by side. Other Shutil Module APIs worth comparing: shutil.copy(), shutil.move(), shutil.rmtree(), shutil.make_archive(), shutil.get_archive_formats(), shutil.disk_usage(). Both belong to the Shutil Module category in the Python Reference documentation. Try both in the Python playground to see the behavioral difference live.