import os
import json
import cv2
import shutil
import random
import numpy as np
import glob
import matplotlib.pyplot as plt
random.seed(0)
n=0
def Reove(picturepath):
for root,dirs,files in os.walk(picturepath):
for file in files:
n+=1
path=os.path.join(root,file)
os.remove(path)
print("删除了{}张 ".format(n))
def Copy(srcpath,dstpath):
for root,dirs,files in os.walk(srcpath):
for file in files:
shutil.copyfile(os.path.join(root,file),os.path.join(dstpath,file))#拷贝出来
n+=1
print("第{}张 ".format(n))
if __name__ == "__main__":
#需要删除资料的文件夹路径
picturepath='C:XXXXXXXXXXXXXXXX'
Reove(picturepath)
#需要复制文件的源路径
srcpath='C:XXXXXXXXXXXXXXXX'
#需要复制文件的保存路径
dstpath='C:XXXXXXXXXXXXXXXX'
Copy(srcpath,dstpath)
python 文件夹下资料的一键删除或复制功能
于 2024-01-24 21:28:38 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)