Created
December 27, 2017 06:35
-
-
Save comzyh/d93336eb4cfda4becee2119ae465c769 to your computer and use it in GitHub Desktop.
Add BOM to .h file
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
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