Dec-20-2019, 06:47 PM
join path together for both scr and dst,then get absolute path for both and copying should work fine.
Example tested.
Example tested.
import os import shutil from os.path import join src = r'E:\div_code\pan' dst = r'E:\div_code\new_folder' for root, dirs, files in os.walk(src): for file in files: if file.endswith(('.txt', '.md')): shutil.copyfile(join(src, file), join(dst, file))