#!/usr/bin/python import sys,getopt,os; opts, args = getopt.getopt(sys.argv[1:],"r:R:l:L:") RUNS = [] loc = 'localdir' for d in os.listdir(loc): if d.startswith('run3'): RUNS.append(d) RUNS.sort() outf = 'hodoMPV.dat' OUTF = open(outf,'w') for d in RUNS: inf1 = loc+'/'+d+'/hodoscope_peak.dat' if os.path.isfile(inf1): INF1 = open(inf1) r = d[3:8] lin = r for line1 in INF1: val = line1.split() lin += ' '+val[1] if int(val[0]) == 128: break; INF1.close() lin += '\n' OUTF.write(lin) OUTF.close()