Here is below code which will move and replace individual file
import shutil
import os
src = 'scrFolder'
dst = './dstFolder/'
filelist = []
files = os.listdir( src )
for filename in files:
filelist.append(filename)
fullpath = src + '/' + filename
shutil.move(fullpath, dst)
If i execute same command and moving file which already existed in dst folder
i am getting shutil.Error: Destination path './dstFolder/file.txt' already exists
how to do move and replace if same file name already existed
If you specify the full path to the destination (not just the directory) then
shutil.move
will overwrite any existing file:I got it to overwrite by providing a full path for both source and target in the move command... remember to add double slash for Windows paths.