Skip to content

Instantly share code, notes, and snippets.

@RichardNesbitt
Created December 10, 2024 20:56
Show Gist options
  • Save RichardNesbitt/cdff31ba92de6c0a2b4164c7ad7d0c66 to your computer and use it in GitHub Desktop.
Save RichardNesbitt/cdff31ba92de6c0a2b4164c7ad7d0c66 to your computer and use it in GitHub Desktop.
Dump a copy of all .ts and .tsx files into a separate folder.
#!/bin/bash
# Usage: ./script.sh <source_directory> <destination_directory>
SOURCE_DIR="${1:-.}" # Use current directory if no source specified
DEST_DIR="${2:-./typescript_files}" # Default destination directory
# Create destination directory if it doesn't exist
mkdir -p "$DEST_DIR"
# Find all .ts and .tsx files, excluding node_modules directories, and process them
find "$SOURCE_DIR" -type f \( -name "*.ts" -o -name "*.tsx" \) -not -path "*/node_modules/*" -print0 | while IFS= read -r -d $'\0' file; do
# Get the relative path from source directory
rel_path=${file#"$SOURCE_DIR"}
rel_path=${rel_path#/} # Remove leading slash
# Create new filename by replacing directory separators with colons
# and adding @ prefix
new_name="@:${rel_path//\//:}"
# Copy file to destination with new name
cp "$file" "$DEST_DIR/$new_name"
done
echo "Files have been copied to $DEST_DIR"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment