# 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')