Created
June 27, 2012 11:40
-
-
Save nojvek/3003526 to your computer and use it in GitHub Desktop.
Convert Spaces to Tabs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import re | |
#whatever filter you would like to apply | |
os.system('find * -type f | egrep -v ".svn" | egrep "\.(js|mustache|css|html|txt|less|sass|as|cfml|mxml)$" > /tmp/sourcefiles.txt') | |
with open('/tmp/sourcefiles.txt') as f: | |
files = f.read().strip().split("\n") | |
for file in files: | |
print "Processing", file | |
with open(file, 'r') as f: #read the file | |
lines = f.read().split("\n") | |
for i,line in enumerate(lines): | |
if re.search("^\s+", line): #if white space is detected at start of line replace it | |
lines[i] = line.replace(" ","\t") | |
with open(file, 'w') as f: | |
str = "\n".join(lines) | |
f.write(str) | |
#print str |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi - can you please send me an email I have a small technical issue I might be able to pay you to help me with - thanks!