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
    原文作者:小_小_杨_
    原文地址: https://blog.csdn.net/u012235274/article/details/51315214
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞