Created
December 11, 2018 07:24
-
-
Save alitoufighi/55668b83d90b32ac884048dc36c65772 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# open all files with .h in directory | |
# add #ifndef _[FILENAME_H]_\n#define _[FILENAME_H]_ in the beginning of the file | |
# add #endif at the end of the file | |
import glob, os, sys | |
def name_header_creator(filename): | |
name = filename.split('.')[0].upper() | |
header_name = f'_{name}_H_' | |
res = f'#ifndef {header_name}\n#define {header_name}' | |
return res | |
if(len(sys.argv) != 2): | |
print("Enter path to your directory in first argument.") | |
exit() | |
os.chdir(sys.argv[1]) | |
for file in glob.glob("*.h"): | |
# print(file) | |
with open(file, 'r+') as f: | |
content = f.read() | |
f.seek(0, 0) | |
f.write(name_header_creator(file).rstrip('\r\n') + '\n' + content + '\n' + '#endif'.rstrip('\r\n') + '\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment