This bash script is designed to flatten your project file structure, making it easier to upload files to Claude.ai's new project files feature. It copies files from a source directory to a destination directory, renaming them based on their original path to maintain uniqueness and traceability.
For example, it will take a folder that looks like this:
/src
/app
Button.tsx
Card.tsx
and return a single folder like this:
/
src_app_Buton.tsx
src_app_Card.tsx
-
Simplified Upload Process: Claude.ai's project files feature has limitations on directory structure. This script flattens your project structure, making it easier to upload and work with your files in Claude.ai.
-
Preserves File Relationships: By encoding the original file path into the new filename, you can easily trace back where each file came from in your original project structure.
-
Handles Name Conflicts: Files with the same name but in different directories won't overwrite each other, as their new names include their original paths.
-
Selective Copying: The script only copies specific file types (
.ts
,.tsx
,.css
,.sh
) and excludes common directories and files that are typically not needed (likenode_modules
, build outputs, etc.).
-
Save the script as
flatten_copy.sh
in your desired location. -
Modify the
EXCLUDE_PATHS
list to exclude paths from being copied. -
Select which file types to include:
-type f \( -name ".ts" -o -name ".tsx" -o -name ".css" -o -name "*.sh" \)
-
Make the script executable:
chmod +x flatten_copy.sh
-
Run the script with source and destination directories:
./flatten_copy.sh /path/to/source/directory /path/to/destination/directory
- Copies only
.ts
,.tsx
,.css
, and.sh
files. - Excludes common directories and files (e.g.,
node_modules
,.next
, build outputs). - Renames files based on their original path, replacing directory separators with underscores.
- Provides verbose output, showing each file being copied.
- Exits with an error if any file copy operation fails.
- You can modify the
EXCLUDE_PATHS
array to add or remove directories/files to exclude. - To include additional file types, modify the
-name
conditions in thefind
command.
- Always test the script on a small subset of your project before running it on your entire codebase.
- Ensure you have write permissions for the destination directory.
- The script will overwrite files in the destination directory if they have the same name as the flattened files.
If you encounter any issues:
- Check that you have the necessary permissions for both source and destination directories.
- Ensure the source directory path is correct and contains the files you expect.
- Check the console output for any error messages about failed copy operations.