This repository contains two scripts, code_print.sh
and print_code.py
, that allow you to print the code contents of files in a directory and its subdirectories, along with their full file paths. The scripts exclude specified directories, files, and binary encoded files to provide a cleaner output.
- macOS or Linux operating system
- Bash shell (for
code_print.sh
) - Python 3 (for
print_code.py
)
-
Open a terminal and navigate to the directory where you want to run the script.
-
Make the script executable by running the following command:
chmod +x code_print.sh
-
Run the script using the following command:
./code_print.sh
The script will traverse the current directory and its subdirectories, excluding specified directories, files, and binary encoded files. It will print the full file path and code content of each relevant file.
-
Open a terminal and navigate to the directory where you want to run the script.
-
Run the script using the following command:
python print_code.py
The script will traverse the current directory and its subdirectories, excluding specified directories, files, and binary encoded files. It will print the full file path and code content of each relevant file.
Both scripts have predefined lists of directories, files, and file extensions to exclude from the search. You can modify these lists according to your needs:
exclude_dirs
: List of directory names to exclude.exclude_files
: List of file names or patterns to exclude.exclude_extensions
: List of file extensions to exclude
Feel free to update these lists in the respective scripts to customize the exclusion criteria.
Here's an example of the output generated by running either of the scripts:
File: /path/to/directory/file1.txt
This is the content of file1.txt.
------------------------
File: /path/to/directory/subdirectory/file2.py
def hello_world():
print("Hello, World!")
------------------------
Skipping binary file.
------------------------
The script will print the full file path, followed by the code content of each relevant file. Binary encoded files will be skipped with a message indicating so.