python 讀取全部文件名以及路徑,添加固定字符,並且輸出到txt
import os
txtName = "negatives.txt"
f=file(txtName, "a+")
dire="/home/a123/Downloads/OpenCV-Haar-AdaBoost-master/negative_images"
#anchor="/home/a123/Downloads/OpenCV-Haar-AdaBoost-master/positive_images"
for root ,dirs, files in os.walk(dire):
for file_single in files:
test = root+'/'+file_single
refile = file_single[0:8]
#anchort = anchor + refile +'.png'
result = test +'\n'
#result = test + " " +anchort +'\n'
f.write( result)
f.close()
file_single 是每個單個文件名
root是全部文件名
refile = file_single[0:8] 可以選擇表示選擇前8個字符,但是這裏不需要
結果圖