#append ASCIIfiles #author: Felix Boehmer import glob, sys, os options = ["-f","-of"] opts = set(options) pattern = ".dat" def getArgsToNextOpt(stringlist, index) : id = index+1 args = [] while(id < len(stringlist)): if stringlist[id] in options: return args args.append(stringlist[id]) id+=1 return args def cmpDevMapFiles(string1, string2) : num1 = (int)(string1[string1.find(pattern)+len(pattern):]) num2 = (int)(string2[string2.find(pattern)+len(pattern):]) return num1 - num2 for iarg in range(len(sys.argv)) : arg = sys.argv[iarg] if arg == "-f": files = getArgsToNextOpt(sys.argv,iarg) if arg == "-of": outfiles = getArgsToNextOpt(sys.argv,iarg) if len(outfiles) > 1 : print "ERROR: Invalid output file!" print outfile exit outfile = outfiles[0] outfilegiven = 1 if not outfilegiven: print "ERROR: No output file was given!" exit files = sorted(files,cmpDevMapFiles) for f in files: print f print ofile = open(outfile,"w") fcounter = 0 for f in files : ifile = open(f, "r") for l in ifile: ofile.write(l) ofile.close()