Created
February 3, 2022 01:02
-
-
Save MattJeanes/02ba412c576342a1ee8bbbee8c0db880 to your computer and use it in GitHub Desktop.
Convert an entire folder of files from tabs to spaces
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
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