编程语言
首页 > 编程语言> > python读取文件下所有目录并保存为txt文档

python读取文件下所有目录并保存为txt文档

作者:互联网

 1 import os
 2 import cv2 as cv
 3 
 4 path = "E:/codePro/python_pro/Yolo-Faster-XL_QR_pro/QR_Data/test/"
 5 
 6 imgSavePath  = "E:/codePro/python_pro/Yolo-Faster-XL_QR_pro/QR_Data/test_bmp/"
 7 filelist = os.listdir(path)
 8 
 9 nameTxt = "file.txt"
10 txtPathName = path + nameTxt
11 
12 print(txtPathName)
13 
14 f=open(txtPathName,"w")
15 
16 cnt  = 0
17 
18 for item in filelist:
19 
20     print(item)
21     imgName = path +item
22     img = cv.imread(imgName)
23 
24     imgSaveName = imgSavePath + str(cnt)+".bmp"
25     cnt +=1
26 
27     cv.imwrite(imgSaveName, img)
28   
29     f.write( imgSaveName )
30   
31     f.write('\n')      
32 f.close()
View Code

 

标签:imgSaveName,cnt,QR,python,pro,文档,path,txt,cv
来源: https://www.cnblogs.com/zhaopengpeng/p/16033720.html