Skip to content

Instantly share code, notes, and snippets.

@nojvek
Created June 27, 2012 11:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nojvek/3003526 to your computer and use it in GitHub Desktop.
Save nojvek/3003526 to your computer and use it in GitHub Desktop.
Convert Spaces to Tabs
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
@craftfortress
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment