import os # Walk through all directories and subdirectories from the current directory for dirpath, dirnames, filenames in os.walk('.'): # For each file in the directories for filename in filenames: # If the file is a .sy file if filename.endswith('.sy'): filepath = os.path.join(dirpath, filename) with open(filepath, 'r+') as file: content = file.read() # Add '#include "sylib.h"' at the beginning of the file file.seek(0, 0) file.write('#include "sylib.h"\n' + content)