I want to make a python script that recursively copies from src to dest and and I also want to make some rules like it shoudn't copy .py files or .log files. I have to tried ignore_pattern but using shutil.copyfile . All the files are getting copied to the same destination directories. No sub directories are created. Please help me with that.
CODE :
import os
import re
from datetime import datetime
from distutils.file_util import copy_file
file1 = open("E:\Test\upgrade.log","a")
log=""""""
src="E:\Test\src"
dest="E:\Test\dest"
src_files =os.listdir(src)
filtered_files = [i for i in src_files if not re.findall(".bmp",i)]
for file_name in filtered_files:
full_file_name = os.path.join(src, file_name)
log = log + datetime.now().strftime("%d/%m/%Y %H:%M:%S")+" "+ file_name
if os.path.isfile(full_file_name):
log = log + " Copied Successfully to " + dest
copy_file(full_file_name,dest)
log = log + "\n"
file1.write(log)
file1.close()
print(log)
Maybe this can help you: