得到某目录下的某些文件

# -*- coding: cp936 -*-
#程序说明
import os
import string
import re
import glob
def save(fileName):
    infile=open(fileName,'r')
    readline=infile.readlines()
    infile.close()
    for stro in xrange(len(readline)):
        line = readline[stro]
        lineTemp = line[line.index("AM--"):]
        m = re.search(r'(:([1-9]\d*))', lineTemp)
        if m: 
            print line#print m.group(0), m.group(1)
            outfile.write(line)



#for filename in glob.glob('/A/*/low/*.png')
#print filename #输出的是文件的绝对路径
#printer filename.split()[1] 文件名
outfile=open('outfile.txt','w')
for filename in glob.glob('D:\\TestPython\\readTestSpeed\\visitSpeed*.txt'):
    save(filename)
    outfile.write('\n')
outfile.close()


你可能感兴趣的:(OS)