Tutorial
1.you need to have a chatgpt plus account
2. Create a py script to merge the specified files, reference code
#!/usr/bin/env python3
-- coding: utf-8 --
Import required modules
import argparse
import os
def merge_files(input_files, output_file_path):
“”"
Merge the contents of multiple source code files into one output file.
Args:
input_files (list): A list of input file paths.
output_file_path (str): The path of the output file.
"""
try:
# Write content to the output file in UTF-8 encoding, overwrite if exists
with open(output_file_path, 'w', encoding='utf-8') as output_f:
for index, input_file_path in enumerate(input_files):
base_name = os.path.basename(input_file_path) # Get the file name (last part)
content = None
try:
# First try to read the file in binary mode to check UTF-8 encoding
with open(input_file_path, 'rb') as f_binary_check:
binary_content = f_binary_check.read()
# Try strict UTF-8 decoding, print warning if failed
try:
binary_content.decode('utf-8', errors='strict')
# If strict decoding succeeds, still use 'ignore' for consistency and robustness
# Or you can use the decoded content directly, but the requirement is to ignore illegal characters, so reading with 'ignore' is more appropriate
with open(input_file_path, 'r', encoding='utf-8', errors='ignore') as f_in:
content = f_in.read()
except UnicodeDecodeError:
print(f"Warning: File '{base_name}' contains characters that cannot be decoded with UTF-8. These characters will be ignored and processing will continue.")
# Read file content in 'ignore' mode, ignore undecodable characters
with open(input_file_path, 'r', encoding='utf-8', errors='ignore') as f_in:
content = f_in.read()
except FileNotFoundError:
print(f"Error: Source file '{base_name}' not found. Skipped.")
continue # Skip this file and continue with the next
except IOError as e:
print(f"Error: IO error occurred while reading source file '{base_name}': {e}. Skipped.")
continue # Skip this file
except Exception as e:
print(f"Unknown error occurred while processing file '{base_name}': {e}. Skipped.")
continue # Skip this file
if content is not None:
# Write the file name first
output_f.write(f"{base_name}\n")
# Write file start delimiter
output_f.write(f"{' ' * 9}/***** BEGIN {base_name} *****/\n")
# Write the original file content
output_f.write(content)
# Ensure there is a newline between content and END marker if content does not end with a newline
if content and not content.endswith('\n'):
output_f.write('\n')
# Write file end delimiter
output_f.write(f"{' ' * 9}/***** END {base_name} *****/\n")
# If not the last file, add an extra newline between entries for readability
if index < len(input_files) - 1:
output_f.write('\n')
print(f"Successfully merged files into '{output_file_path}'")
except IOError as e:
print(f"Error: Unable to write to output file '{output_file_path}': {e}")
except Exception as e:
print(f"Unknown error occurred during file merging: {e}")
def main():
Create argument parser
parser = argparse.ArgumentParser(description=“Merge multiple source code files into one file, preserving original content and format.”)
# Add input file arguments (one or more)
parser.add_argument(
"input_files",
metavar="FILE",
type=str,
nargs="+", # At least one input file is required
help="List of source file paths to merge."
)
# Fixed output file name as '1.txt'
output_file = "1.txt"
# Parse command line arguments
args = parser.parse_args()
# Call the merge files function
merge_files(args.input_files, output_file)
if name == “main”:
main()
The effect is as shown in the picture.
All you need to do is talk to AI, run the py script, merge all files related to the board in question, including frontend, backend, database, and I’ll send it to someone else You’ll get a merged file of a few thousand lines and upload it to the chatgpt website.
Describe the problem to him, ask for a solution, then send it to cursor, solve it, cost about o3 $0.05 a time
I’ll combine the project structure files for easy AI extraction and merging
Costs have been reduced dozens of times
On a daily basis I use Cursor’s Claude to write code o3 for complex problem bug solving, but cursor’s o3 is super expensive, I used cursor’s o3 once, and it consumed 50,000tokens of my 100 fast requests……
If I remember correctly a plus account can be used 100 times a week o3 for only 20 dollars a month it can be used over 400 times,And just to be clear, I’m not advertising, it’s a lot less expensive.