Move and replace if same file name already exists?

后端 未结 2 1614
北恋
北恋 2020-12-02 14:16

Here is below code which will move and replace individual file:

import shutil
import os
src = \'scrFolder\'
dst = \'./dstFolder/\'
filelist = []

files = os.         


        
2条回答
  •  旧巷少年郎
    2020-12-02 14:55

    If you specify the full path to the destination (not just the directory) then shutil.move will overwrite any existing file:

    shutil.move(os.path.join(src, filename), os.path.join(dst, filename))
    

提交回复
热议问题