Skip to content

Instantly share code, notes, and snippets.

@MattJeanes
Created February 3, 2022 01:02
Show Gist options
  • Save MattJeanes/02ba412c576342a1ee8bbbee8c0db880 to your computer and use it in GitHub Desktop.
Save MattJeanes/02ba412c576342a1ee8bbbee8c0db880 to your computer and use it in GitHub Desktop.
Convert an entire folder of files from tabs to spaces
from glob import iglob
import os
import sys
spaces_per_tab = 4
argc = len( sys.argv )
if argc < 2:
print('no file argument specified')
directory = sys.argv[ 1 ]
for filename in iglob(directory + '**/*.lua', recursive=True):
if not filename.endswith(".lua"):
continue
old_filename = filename + ".old"
os.rename( filename, old_filename )
fn = open( filename, 'wb' )
fo = open( old_filename, 'r' )
for line in fo:
fn.write( line.expandtabs( spaces_per_tab ).encode() )
fn.close()
fo.close()
os.remove( old_filename )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment