Skip to content

Instantly share code, notes, and snippets.

@CristianDeluxe
Last active March 27, 2024 14:41
Show Gist options
  • Save CristianDeluxe/7407d6913267a572eb5897cb2e0074a3 to your computer and use it in GitHub Desktop.
Save CristianDeluxe/7407d6913267a572eb5897cb2e0074a3 to your computer and use it in GitHub Desktop.
Paste ChatGPT Code. This script is designed to traverse a specified folder and its subdirectories, printing the contents of all files found inside, excluding certain folders and files based on predefined criteria. You can then paste this code into an AI chat like ChatGPT
#!/bin/bash
# Script: chatgpt.sh
# Description: Traverse through a specified folder, excluding certain folders and files, and print the contents of all non-excluded files.
# Example: ./chatgpt.sh /path/to/folder
# Check if a folder path is provided
if [ -z "$1" ]; then
echo "Please provide a folder path."
exit 1
fi
# Folder path provided as the first argument
FOLDER="$1"
# Specific folders to exclude (by name, anywhere in the path)
EXCLUDED_FOLDERS=( ".idea" ".vscode" ".git" "__pycache__" )
# Specific files and file extensions to exclude
EXCLUDED_FILES_AND_EXTENSIONS=( "*.db" "*.log" "*.tmp" "*.udb" "*.csv" "*.txt" ".DS_Store" "move_files.sh" ) # Add more extensions here as needed
# Build the exclusion conditions string for folders and files
EXCLUSION_CONDITIONS=""
for folder in "${EXCLUDED_FOLDERS[@]}"; do
[ -n "$EXCLUSION_CONDITIONS" ] && EXCLUSION_CONDITIONS+=" -o"
EXCLUSION_CONDITIONS+=" -path \"*/$folder/*\""
done
for file in "${EXCLUDED_FILES_AND_EXTENSIONS[@]}"; do
EXCLUSION_CONDITIONS+=" -o -name \"$file\""
done
# Use eval with find to apply exclusion conditions and find files
eval "find \"$FOLDER\" -type d \( $EXCLUSION_CONDITIONS \) -prune -o -type f ! \( $EXCLUSION_CONDITIONS \) -print" | while read file; do
# Print the relative path of the file
echo "Path: ${file#$FOLDER/}"
# Print a separator line
echo "---------------------"
# Print the content of the file
cat "$file"
# Print two new lines as separation between files
echo -e "\n\n"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment