# Add \n to end of all lines of all files in the folder! # Careful that you only keep the data files in the folder! # # Call with "python regexp.py" in e.g. PowerShell # # Written by Bjarke Moensted import glob import os print "WARNING: This script will add endline-code to all lines of all files" print " in this directory. Thus it should ONLY contain datafiles!" print " Make sure, that you have backup, just in case..." #Hold script until you want to exit raw_input( ' ... Press enter to proceed ... ' ) #Merciless cleanup: mess = glob.glob('*.tmp') for file in mess: os.remove(file) filelist = glob.glob('*') filelist.remove(__file__) for name in filelist: print "Opening "+name infile = open(name, 'r') temp = name+".tmp" outfile = open(temp, 'w') for line in infile: argh = line.split("\r") for hest in argh: outfile.write(hest+"\n") infile.close() outfile.close() os.remove(name) os.renames(temp, name)