python 查找文件夹下面的所有文件,读取文件

查找文件夹所有文件代码:

import os
FindPath = 'c:/Users/yang/Documents/python/'
FileNames = os.listdir(FindPath)
for file_name in FileNames:
    fullfilename=os.path.join(FindPath,file_name)  
    print fullfilename

输出:

c:/Users/yang/Documents/python/file.txt
c:/Users/yang/Documents/python/file_temp.txt
c:/Users/yang/Documents/python/read_file_name.py

读取文件:为了配合caffe生成文件的要求,每一行存储的是图片文件的名称,然后加标签

fid = open('C:/Users/yang/Documents/python/file_temp.txt','r')
str = fid.readlines()
for line in str:
    linearr = line.strip().split(' ')
    print linearr

你可能感兴趣的:(python)