Copy multiple files in Python

前端 未结 6 1974
野趣味
野趣味 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:40

    If you don't want to copy the whole tree (with subdirs etc), use or glob.glob("path/to/dir/*.*") to get a list of all the filenames, loop over the list and use shutil.copy to copy each file.

    for filename in glob.glob(os.path.join(source_dir, '*.*')):
        shutil.copy(filename, dest_dir)
    

提交回复
热议问题