| import os
|
| import shutil
|
|
|
| def copy_folder(source_folder, destination_folder):
|
| if not os.path.exists(destination_folder):
|
| os.makedirs(destination_folder)
|
|
|
| for root, dirs, files in os.walk(source_folder):
|
| # Get the relative path from the source folder
|
| relative_path = os.path.relpath(root, source_folder)
|
| destination_path = os.path.join(destination_folder, relative_path)
|
|
|
| if not os.path.exists(destination_path):
|
| os.makedirs(destination_path)
|
|
|
| for file in files:
|
| source_file = os.path.join(root, file)
|
| destination_file = os.path.join(destination_path, file)
|
| shutil.copy2(source_file, destination_file)
|
| # If you want to move the files instead of copying, you can use shutil.move() instead of shutil.copy2()
|
|
|
| # Example usage
|
| source_folder = '/path/to/source/folder'
|
| destination_folder = '/path/to/destination/folder'
|
|
|
| copy_folder(source_folder, destination_folder)
|