Skip to content

Instantly share code, notes, and snippets.

@comzyh
Created December 27, 2017 06:35
Show Gist options
  • Save comzyh/d93336eb4cfda4becee2119ae465c769 to your computer and use it in GitHub Desktop.
Save comzyh/d93336eb4cfda4becee2119ae465c769 to your computer and use it in GitHub Desktop.
Add BOM to .h file
import os
import os.path
import sys
import codecs
def main():
print(sys.argv[1])
for root, dirs, files in os.walk(sys.argv[1]):
for file in files:
if file.endswith('.h'):
filename = os.path.join(root, file)
with open(filename, 'rb+') as f:
content = f.read(3)
# print(content, ord(content))
if content != codecs.BOM_UTF8:
content += f.read()
f.seek(0)
f.write(codecs.BOM_UTF8)
f.write(content)
print(filename)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment