#!/apps/python/PRO/bin/python import sys, getopt, os loc = '/cache/halld/RunPeriod-2016-02/recon/ver01/tree_tof_eff/' RunDirs = [] RUNS = [] for d in os.listdir(loc): run = d R = int(run) RunDirs.append(d) RUNS.append(R) files = [] ndir = loc+d for f in os.listdir(ndir): if f.endswith('root'): files.append(f) files.sort() cmd = 'hadd localdir/hd_root_'+d+'.root ' for f in files: cmd += ndir+'/'+f+' ' if len(files)>0: print cmd os.system(cmd)