2 Searches recursive all files "*.h" and "*.hpp" and adds line "include \"sick_scan/sick_scan_base.h\" at the beginning of all files.
5 python3 add_sick_scan_base_header.py
13 subfolders, files = [], []
14 for f
in os.scandir(dir):
16 for exclude
in excludes:
23 subfolders.append(f.path.replace(
"\\",
"/"))
25 if os.path.splitext(f.name)[1].lower()
in extensions:
26 files.append(f.path.replace(
"\\",
"/"))
27 for dir
in list(subfolders):
33 if __name__ ==
'__main__':
36 exclude_string =
"#include \"sick_scan/sick_scan_base.h\""
37 additional_line =
"#include \"sick_scan/sick_scan_base.h\" /* Base definitions included in all header files, added by add_sick_scan_base_header.py. Do not edit this line. */\n"
39 header_files =
scandirectory(folder, [
".h",
".hpp"], [
"sick_scan_base.h",
"sick_scan_api.h"])
40 for file
in header_files:
42 with open(file,
"r")
as f:
44 if content !=
"" and not content.startswith(exclude_string):
45 with open(file,
"w")
as f:
46 f.write(additional_line)
48 print(
"{}: added \"{} ...\"".format(file, additional_line[:37]))
50 print(
"{}: skipped".format(file))
51 print(
"add_sick_scan_base_header.py finished.")