Skip to content

Instantly share code, notes, and snippets.

@Jinmo
Last active March 29, 2019 16:54
Show Gist options
  • Save Jinmo/44dc4d0e0dc662a5902a to your computer and use it in GitHub Desktop.
Save Jinmo/44dc4d0e0dc662a5902a to your computer and use it in GitHub Desktop.
UTF-8 BOM adder
import os
rootdir = 'EDIT_HERE'
for root, subdirs, files in os.walk(rootdir):
for file in files:
if file.endswith('.c') or file.endswith('.h'):
f = open(root + '/' + file, 'rb')
if f.read(3) != '\xEF\xBB\xBF':
try:
f.seek(0, 0)
data = f.read()
data.decode('cp949')
except:
f.close()
f = open(root + '/' + file, 'wb')
f.write('\xEF\xBB\xBF' + data)
print root + '/' + file
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment