Skip to content

Instantly share code, notes, and snippets.

@ag7
Created March 6, 2015 14:37
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 ag7/020b50bc4dbc47eca6b9 to your computer and use it in GitHub Desktop.
Save ag7/020b50bc4dbc47eca6b9 to your computer and use it in GitHub Desktop.
convert tabs to spaces inside source files
#!/usr/bin/env python
import sys, os, subprocess
# specify the source file extension here
sources = [".cpp", ".h"]
if __name__ == "__main__":
for root, _, files in os.walk(os.path.dirname(os.path.realpath(__file__))):
for fname, fext in [os.path.splitext(f) for f in files]:
if fext.lower() in sources:
src = os.path.join(root, fname + fext)
with open(src + ".out", "w") as fout:
subprocess.call(["expand", "-t", "4", "-i", src], stdout=fout)
os.rename(src + ".out", src)
sys.exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment