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 exists?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…