python从一个目录中复制全部文件图片至另一个目录中,及删除指定目录中的图片

时间:2021-05-26 20:59:54
import shutil
import os

#目录自己改一下即可,复制
path = "./static/imgs/"   
new_path = "./static/upload/"

for file in os.listdir(path):
    full_file = os.path.join(path, file)
    new_full_file = os.path.join(new_path, file)
    shutil.copy(full_file, new_full_file)


# 删除目录,在新建相同目录
shutil.rmtree(path)
os.mkdir(path)