python: copy folder and content (including subfolders) to specified directory

import yaml
import us
import shutil


def copyHistorySession():
    source_path5048 = r'D:\sourse'
    target_path5048 = r'D:\target'
    if not os.path.exists(target_path5048):
        # If the original folder does not exist in the target path, create it
        os.makedirs(target_path5048)
    if os.path.exists(source_path5048):
        # If the original folder exists in the target path, delete it first
        shutil.rmtree(target_path5048)
    shutil.copytree(source_path5048, target_path5048)
    print('copy 5048 History Session finished!')

Guess you like

Origin blog.csdn.net/zhangliang0000/article/details/127492996