# -*- coding: utf-8 -*-
import os
import cv2 as cv
#path = "D:\\yolodata\\txtImage\\tiny" # 设置路径
path=u"D:\\yolodata\\txtImage\\tinyImage"
pathform = u"D:\\yolodata\\txtImage\\tiny"
dirs = os.listdir(path) # 获取指定路径下的文件
count=0
# 获取指定路径下所有指定后缀的文件
# dir 指定路径
# ext 指定后缀,链表&不需要带点 或者不指定。例子:['xml', 'java']
def GetFileFromThisRootDir(dir,ext = None):
allfiles = []
needExtFilter = (ext != None)
for root,dirs,files in os.walk(dir):
for filespath in files:
filepath = os.path.join(root, filespath)
extension = os.path.splitext(filepath)[1][1:]
if needExtFilter and extension in ext:
allfiles.append(filepath)
elif not needExtFilter:
allfiles.append(filepath)
return allfiles
files=GetFileFromThisRootDir(pathform,".jpg")
allcount= len(files)
allcount=20000
for fl in files:
print fl
if ( (count < allcount)):
picname = str(count) + '.jpg'
os.rename(fl, os.path.join(pathform, picname))
count = count + 1
allFileNum = allFileNum + 1