python 复制 剪切文件

134 阅读1分钟

导入包


from shutil import copy
from shutil import copyfile
from shutil import move

复制文件

Ori_Path = '/Users/1.txt'
Tar_Path = '/Users/2.txt'
copyfile(Ori_Path, Tar_Path)

复制文件夹内所有文件 到另外一个文件夹


from shutil import copy
import os
 
Ori_Path = '/Users/gao/Documents/Coding/ori_img'
Tar_Path = '/Users/gao/Documents/Coding/copy_img'
img_names = os.listdir(Ori_Path)
 
for img_name in img_names:
    ori_img_path = Ori_Path + '/' + img_name
    copy(ori_img_path, Tar_Path)

剪切文件

Ori_Path = '/Users/1.txt'
floder_damage = "/home/damage"
move(Ori_Path, floder_damage)