Copy multiple files in Python

前端 未结 6 1989
野趣味
野趣味 2020-11-28 23:25

How to copy all the files present in one directory to another directory using Python. I have the source path and the destination path as string.

6条回答
  •  心在旅途
    2020-11-28 23:25

    import os
    import shutil
    os.chdir('C:\\') #Make sure you add your source and destination path below
    
    dir_src = ("C:\\foooo\\")
    dir_dst = ("C:\\toooo\\")
    
    for filename in os.listdir(dir_src):
        if filename.endswith('.txt'):
            shutil.copy( dir_src + filename, dir_dst)
        print(filename)
    

提交回复
热议问题