Row 85995
Content Data
This page contains data entry 85995 from the Axioma AXP content repository. The structured data below represents the complete record for this entry.
I'm sharing this script that allows you to send the contents of multiple code files to AI models like ChatGPT or Claude for analysis more quickly than manual copy/pasting each one.
It combines the relevant files into a single text file on your machine that can then be uploaded manually to ChatGPT or a different AI, or even used for a different purpose entirely.
(Or it can instead read the directory structure of the specified project and put that structure into a text file)
Here are some examples of running the script:
python [scanner.py](http://scanner.py/) ‘../Documents/my\_project’ fc None None
\^Scans each of the files in “my\_project”, including ones in subdirectories, and writes everything into a text file (called “code.txt”) which can then be sent to ChatGPT
python [scanner.py](http://scanner.py/) ‘../Documents/my\_project’ ds None None
\^Scans the directory structure of “my\_project” and writes that structure into a text file (called “directory\_structure.txt”)
python [scanner.py](http://scanner.py/) '../Git Repositories/excalidraw' fc None LanguageList.tsx,index.html
\^Scans the files in “excalidraw” but excludes files named "LanguageList.tsx" and “index.html”
python [scanner.py](http://scanner.py/) '../Git Repositories/excalidraw' fc +excalidraw-app,packages None
\^Scans “excalidraw” but only reads files within the subdirectories named “excalidraw-app” and “packages”
This is what each argument means:
Argument 0: File name of this script
Argument 1: Path of the project directory to focus on
Argument 2: ‘fc’ if you want the file contents to be written to “code.txt”, or ‘ds’ if you want the directory structure to be written to “directory\_structure.txt”
Argument 3: Comma-separated list of subdirectories within the main directory that you want to exclude from the output. Or, if you instead want to focus solely on these directories and exclude everything else, put ‘+’ at the beginning of the list. Or, just put “None” to skip over this argument.
Argument 4: Same as argument 3, but for files instead of subdirectories
Argument 5: Optional argument specifying the maximum recursion depth
This is the GitHub link: [https://github.com/johnd99/Codebase-Scanner](https://github.com/johnd99/Codebase-Scanner)
This is the code itself for you to use/modify however:
import os import sys def scan_directory(input_directory, mode, skip_dir, selected_directories, skip_files, selected_files, total_depth): # This list can be extended file_extensions = ('.txt', '.md', '.py', '.js', '.html', '.css', '.scss', '.java', '.cpp', '.c', '.h', '.php', '.rb', '.cs', '.swift', '.go', '.rs', '.ts', '.tsx', '.scala', '.lua', '.pl', '.sh', '.bat', '.ps1', '.json') file_count = 0 def has_match(path, my_set): names = path.split('\\') for name in names: if name in my_set: return True return False def read_files_recursive(directory, cur_depth): # Note: This can take a while to run for very large amounts of text nonlocal file_count if cur_depth <= total_depth: for entry in os.scandir(directory): if entry.is_dir() and not entry.name.startswith('.'): if not (skip_dir and entry.name in selected_directories): read_files_recursive(entry.path, cur_depth + 1) elif entry.is_file() and entry.name.endswith(file_extensions): if skip_dir or has_match(entry.path, selected_directories): if skip_files != (entry.name in selected_files): # Can't have both be true or both be false try: with open(entry.path, 'r', encoding='utf-8') as f: content = f.read() absolute_path = os.path.abspath(entry.path) outf.write(f'--- CONTENT OF {absolute_path} ---\n\n{content}\n\n\n\n') file_count += 1 except UnicodeDecodeError as e: print(f"Skipping file due to encoding issue: {entry.path}. Error: {e}") except IOError as e: print(f"Skipping inaccessible file: {entry.path}. Error: {e}") def read_directory_structure_recursive(directory, cur_depth, indentation): nonlocal file_count if cur_depth <= total_depth: for entry in os.scandir(directory): if entry.is_dir() and not entry.name.startswith('.'): if not (skip_dir and entry.name in selected_directories): line = indentation + entry.name + '\n' outf.write(line) read_directory_structure_recursive(entry.path, cur_depth + 1, indentation + " ") elif entry.is_file() and entry.name.endswith(file_extensions): if skip_dir or has_match(entry.path, selected_directories): if skip_files != (entry.name in selected_files): # Can't have both be true or both be false line = indentation + entry.name + '\n' outf.write(line) file_count += 1 if mode == 'fc': with open('code.txt', 'w', encoding='utf-8') as outf: read_files_recursive(input_directory, 1) else: with open('directory_structure.txt', 'w', encoding='utf-8') as outf: read_directory_structure_recursive(input_directory, 1, "") result = str(file_count) + " files" print(result) def main(): num_args = len(sys.argv) if not (num_args == 5 or num_args == 6): print("Script needs 5-6 arguments") sys.exit(1) input_directory = sys.argv[1] # Codebase to scan mode = sys.argv[2] if not (mode == 'fc' or mode == 'ds'): # 'File contents' or 'directory structure' print("Invaid mode") sys.exit(1) skip_dir = True selected_directories = set() if sys.argv[3] == "None": # Don't skip over any directories pass elif sys.argv[3][0] == '+': skip_dir = False selected_directories.update(sys.argv[3][1:].split(',')) # Include files within these directories, skip everything else else: selected_directories.update(sys.argv[3].split(',')) # Skip files within these directories skip_files = True selected_files = set() if sys.argv[4] == "None": # Don't skip over any files pass elif sys.argv[4][0] == '+': skip_files = False selected_files.update(sys.argv[4][1:].split(',')) # Include these files, skip everything else else: selected_files.update(sys.argv[4].split(',')) # Skip these files depth = float('inf') # Indicates the max recursion depth, optional argument if num_args == 6: if sys.argv[5].isdigit(): depth = int(sys.argv[5]) else: print("Invalid depth") sys.exit(1) scan_directory(input_directory, mode, skip_dir, selected_directories, skip_files, selected_files, depth) if __name__ == '__main__': main()
| Field | Value |
|---|---|
| text | I'm sharing this script that allows you to send the contents of multiple code files to AI models like ChatGPT or Claude for analysis more quickly than manual copy/pasting each one. It combines the relevant files into a single text file on your machine that can then be uploaded manually to ChatGPT or a different AI, or even used for a different purpose entirely. (Or it can instead read the directory structure of the specified project and put that structure into a text file) Here are some examp… |
| label | r/chatgpt |
| dataType | post |
| communityName | r/ChatGPT |
| datetime | 2024-05-24 |
| username_encoded | Z0FBQUFBQm5Lak1vUXRkem1QSTRSLTlRdDQ2ZUh4OVBzZThUN2JSWERLal96bVlfY1NNdlBtWFlYM0J3c051TWhFWkdqN004N1RnUmUwbDRINDV1b280eVB5OUxuX2hfYVE9PQ== |
| url_encoded | Z0FBQUFBQm5Lak81ZGVtYUlfNVBfVzdIdE10dDkyeWpNZWxpTTUxXzU3a3o2aHpWZnBtclM5TUE2NGVPWVkySnVxeS1VZ25FajlGcEIzZlpYTXFhYUsxcXUxR1U3Nm1hN3dhNGFWbzMxV21WclBXNDhXNWhvMzJZTzJYRkFUS29UTHJUc3NJZkhQNGREbzdtaGRNc3Y2cDd3YWFodGhwMS1QWHhrd3FKMnJBWGZ4X1pyZ1pVQkNsbV91dnFjLWw0dm9vNm1QZEhURmxtYkU0dDdabkxQR0tUQXhJUlU2el9yQT09 |
Raw Record
{
"text": "I'm sharing this script that allows you to send the contents of multiple code files to AI models like ChatGPT or Claude for analysis more quickly than manual copy/pasting each one.\n\nIt combines the relevant files into a single text file on your machine that can then be uploaded manually to ChatGPT or a different AI, or even used for a different purpose entirely.\n\n(Or it can instead read the directory structure of the specified project and put that structure into a text file)\n\nHere are some examples of running the script:\n\npython [scanner.py](http://scanner.py/) ‘../Documents/my\\_project’ fc None None\n\n\\^Scans each of the files in “my\\_project”, including ones in subdirectories, and writes everything into a text file (called “code.txt”) which can then be sent to ChatGPT\n\n \n\npython [scanner.py](http://scanner.py/) ‘../Documents/my\\_project’ ds None None\n\n\\^Scans the directory structure of “my\\_project” and writes that structure into a text file (called “directory\\_structure.txt”)\n\n \n\npython [scanner.py](http://scanner.py/) '../Git Repositories/excalidraw' fc None LanguageList.tsx,index.html\n\n\\^Scans the files in “excalidraw” but excludes files named \"LanguageList.tsx\" and “index.html”\n\n \n\npython [scanner.py](http://scanner.py/) '../Git Repositories/excalidraw' fc +excalidraw-app,packages None\n\n\\^Scans “excalidraw” but only reads files within the subdirectories named “excalidraw-app” and “packages”\n\n \n\nThis is what each argument means:\n\nArgument 0: File name of this script\n\nArgument 1: Path of the project directory to focus on\n\nArgument 2: ‘fc’ if you want the file contents to be written to “code.txt”, or ‘ds’ if you want the directory structure to be written to “directory\\_structure.txt”\n\nArgument 3: Comma-separated list of subdirectories within the main directory that you want to exclude from the output. Or, if you instead want to focus solely on these directories and exclude everything else, put ‘+’ at the beginning of the list. Or, just put “None” to skip over this argument.\n\nArgument 4: Same as argument 3, but for files instead of subdirectories\n\nArgument 5: Optional argument specifying the maximum recursion depth\n\n \n\nThis is the GitHub link: [https://github.com/johnd99/Codebase-Scanner](https://github.com/johnd99/Codebase-Scanner)\n\nThis is the code itself for you to use/modify however:\n\n import os\n import sys\n \n \n def scan_directory(input_directory, mode, skip_dir, selected_directories, skip_files, selected_files, total_depth):\n \n # This list can be extended\n file_extensions = ('.txt', '.md', '.py', '.js', '.html', '.css', '.scss', '.java', '.cpp', '.c', '.h', '.php', '.rb', '.cs', '.swift', '.go', '.rs', '.ts', '.tsx', '.scala', '.lua', '.pl', '.sh', '.bat', '.ps1', '.json')\n \n file_count = 0\n \n def has_match(path, my_set):\n names = path.split('\\\\')\n for name in names:\n if name in my_set:\n return True\n return False\n \n \n def read_files_recursive(directory, cur_depth): # Note: This can take a while to run for very large amounts of text\n nonlocal file_count\n if cur_depth <= total_depth:\n for entry in os.scandir(directory):\n if entry.is_dir() and not entry.name.startswith('.'):\n if not (skip_dir and entry.name in selected_directories):\n read_files_recursive(entry.path, cur_depth + 1)\n elif entry.is_file() and entry.name.endswith(file_extensions):\n if skip_dir or has_match(entry.path, selected_directories):\n if skip_files != (entry.name in selected_files): # Can't have both be true or both be false\n try:\n with open(entry.path, 'r', encoding='utf-8') as f:\n content = f.read()\n absolute_path = os.path.abspath(entry.path)\n outf.write(f'--- CONTENT OF {absolute_path} ---\\n\\n{content}\\n\\n\\n\\n')\n file_count += 1\n except UnicodeDecodeError as e:\n print(f\"Skipping file due to encoding issue: {entry.path}. Error: {e}\")\n except IOError as e:\n print(f\"Skipping inaccessible file: {entry.path}. Error: {e}\")\n \n \n def read_directory_structure_recursive(directory, cur_depth, indentation):\n nonlocal file_count\n if cur_depth <= total_depth:\n for entry in os.scandir(directory):\n if entry.is_dir() and not entry.name.startswith('.'):\n if not (skip_dir and entry.name in selected_directories):\n line = indentation + entry.name + '\\n'\n outf.write(line)\n read_directory_structure_recursive(entry.path, cur_depth + 1, indentation + \" \") \n elif entry.is_file() and entry.name.endswith(file_extensions):\n if skip_dir or has_match(entry.path, selected_directories):\n if skip_files != (entry.name in selected_files): # Can't have both be true or both be false\n line = indentation + entry.name + '\\n'\n outf.write(line)\n file_count += 1\n \n if mode == 'fc':\n with open('code.txt', 'w', encoding='utf-8') as outf:\n read_files_recursive(input_directory, 1)\n else:\n with open('directory_structure.txt', 'w', encoding='utf-8') as outf:\n read_directory_structure_recursive(input_directory, 1, \"\")\n \n result = str(file_count) + \" files\"\n print(result)\n \n \n \n def main():\n num_args = len(sys.argv)\n if not (num_args == 5 or num_args == 6):\n print(\"Script needs 5-6 arguments\")\n sys.exit(1)\n \n input_directory = sys.argv[1] # Codebase to scan\n \n mode = sys.argv[2]\n if not (mode == 'fc' or mode == 'ds'): # 'File contents' or 'directory structure'\n print(\"Invaid mode\")\n sys.exit(1)\n \n skip_dir = True\n selected_directories = set()\n if sys.argv[3] == \"None\": # Don't skip over any directories\n pass\n elif sys.argv[3][0] == '+':\n skip_dir = False\n selected_directories.update(sys.argv[3][1:].split(',')) # Include files within these directories, skip everything else\n else:\n selected_directories.update(sys.argv[3].split(',')) # Skip files within these directories\n \n skip_files = True\n selected_files = set()\n if sys.argv[4] == \"None\": # Don't skip over any files\n pass\n elif sys.argv[4][0] == '+':\n skip_files = False\n selected_files.update(sys.argv[4][1:].split(',')) # Include these files, skip everything else\n else:\n selected_files.update(sys.argv[4].split(',')) # Skip these files\n \n depth = float('inf') # Indicates the max recursion depth, optional argument\n if num_args == 6:\n if sys.argv[5].isdigit():\n depth = int(sys.argv[5])\n else:\n print(\"Invalid depth\")\n sys.exit(1)\n \n scan_directory(input_directory, mode, skip_dir, selected_directories, skip_files, selected_files, depth)\n \n \n if __name__ == '__main__':\n main()",
"label": "r/chatgpt",
"dataType": "post",
"communityName": "r/ChatGPT",
"datetime": "2024-05-24",
"username_encoded": "Z0FBQUFBQm5Lak1vUXRkem1QSTRSLTlRdDQ2ZUh4OVBzZThUN2JSWERLal96bVlfY1NNdlBtWFlYM0J3c051TWhFWkdqN004N1RnUmUwbDRINDV1b280eVB5OUxuX2hfYVE9PQ==",
"url_encoded": "Z0FBQUFBQm5Lak81ZGVtYUlfNVBfVzdIdE10dDkyeWpNZWxpTTUxXzU3a3o2aHpWZnBtclM5TUE2NGVPWVkySnVxeS1VZ25FajlGcEIzZlpYTXFhYUsxcXUxR1U3Nm1hN3dhNGFWbzMxV21WclBXNDhXNWhvMzJZTzJYRkFUS29UTHJUc3NJZkhQNGREbzdtaGRNc3Y2cDd3YWFodGhwMS1QWHhrd3FKMnJBWGZ4X1pyZ1pVQkNsbV91dnFjLWw0dm9vNm1QZEhURmxtYkU0dDdabkxQR0tUQXhJUlU2el9yQT09"
}
Entry Information
- Entry ID: 85995
- Repository: Axioma AXP
- Dataset: arrmlet/reddit_dataset_36
- Total Entries: 100,000