Created
December 10, 2024 20:56
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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