Hello everyone
I have a question
How to use python to copy files in a folder to another folder?
I think you can use the following program for your reference
import os
import shut-off
# copy folder
copyDir = 'C:/Users/test/Desktop/tmp/CCCC/'
# Copy the folder to be placed
putDir = 'C:/Users/test/Desktop/tmp/PPPP/'
for root, dirs, files in os. walk(copyDir):
# For single-level replication of files
for fileName in files:
# Get the full path of the file to be copied
fileP = root + '/' + fileName
# Get the full path where the file to be copied is placed
newFP = putDir + '/' + fileName
# Make a copy (files will be overwritten directly)
shutil. copyfile(
fileP,
newFP
)
Of course this is purely for single-layer folder copy
If you want to keep the folder structure, you can add the action of adding a new folder
For your reference

Message Board
Feel free to leave suggestions and share! Thanksgiving!