赞
踩
因为有需求,要将图片分流到8个文件夹,并且做到平均分配,所以花了一天写了一个,代码如下:
- import os
- import shutil
- import time
- import sys
- import glob
-
- path = 'C:/Users/8190741/Desktop/TapeAIR_GaP/img/'#待移动图片文件路径
- newPath = 'C:/Users/8190741/Desktop/TapeAIR_GaP/{}'#存放的新的图片文件路径
-
- def list_all_files(rootdir):
- """
- 传入文件夹路径,将当前文件夹下的所有文件都找出来
- """
- _files = []
- list = os.listdir(rootdir) #列出文件夹下所有的目录与文件
- for i in range(0,len(list)):
- path = os.path.join(rootdir,list[i])
- if os.path.isfile(path):
- _files.append(path)
- return _files
-
- def png_files(rootdir):
- """
- 通过list_all_files方法获得所有文件后再进行查找PNG图片
- """
- list_name =[]
- _fs = list_all_files(rootdir) #每个文件的绝对路径
- import re
- for path in _fs:
- path = path.replace('\\','/')
- if path.endswith('PNG') or path.endswith

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。