import os import sys def merge_qt_files(project_dir, output_file="master.txt"): # File extensions to include (case-insensitive) TARGET_EXTENSIONS = {'.cpp', '.qml', '.cmake', '.qrc','.h','.txt', '.rs', '.wit'} # Specific filenames to include (e.g., CMake build files) TARGET_FILES = {'cmakelists.txt'} # Directories to completely skip SKIP_DIRS = {'build','target','dist','out','bin','obj','.git','.svn','.hg','bex-data','.bex-data','plugins', 'CMakeFiles'} project_dir = os.path.abspath(project_dir) print(f"🔍 Scanning: {project_dir}") with open(output_file, 'w', encoding='utf-8') as master: for dirpath, dirnames, filenames in os.walk(project_dir): # Remove skipped folders so os.walk doesn't descend into them dirnames[:] = [d for d in dirnames if d not in SKIP_DIRS] for filename in filenames: _, ext = os.path.splitext(filename) # Check if file matches extension or exact name if ext.lower() in TARGET_EXTENSIONS or filename.lower() in TARGET_FILES: filepath = os.path.join(dirpath, filename) rel_path = os.path.relpath(filepath, project_dir) try: # errors='ignore' skips problematic characters instead of crashing with open(filepath, 'r', encoding='utf-8', errors='ignore') as f: content = f.read() master.write(f"# File: {rel_path}\n") master.write(content) master.write("\n\n") # Separator between files except Exception as e: master.write(f"# Error reading {rel_path}: {e}\n\n") print(f"✅ Done! Merged all files into '{output_file}'.") if __name__ == "__main__": # Use the first command-line argument as the folder, otherwise use current directory folder = sys.argv[1] if len(sys.argv) > 1 else "." merge_qt_files(folder)