Skip to content

Instantly share code, notes, and snippets.

@jerturowetz
Created January 22, 2025 19:15
Show Gist options
  • Save jerturowetz/a5e04837ce75d19827a33f2c8bc24c05 to your computer and use it in GitHub Desktop.
Save jerturowetz/a5e04837ce75d19827a33f2c8bc24c05 to your computer and use it in GitHub Desktop.
Merge folders from google drive zip
#!/bin/bash
# Check if at least two folder names are provided
if [ "$#" -lt 2 ]; then
echo "Usage: $0 <source_folder1> <source_folder2> ... <destination_folder>"
exit 1
fi
# Get the destination folder (the last argument)
DESTINATION="${@: -1}"
# Ensure the destination folder exists
if [ ! -d "$HOME/Downloads/$DESTINATION" ]; then
echo "Creating destination folder: $DESTINATION"
mkdir -p "$HOME/Downloads/$DESTINATION"
fi
# Iterate over all source folders except the last one (destination)
for SRC in "$@"; do
if [ "$SRC" != "$DESTINATION" ]; then
SOURCE_PATH="$HOME/Downloads/$SRC"
DEST_PATH="$HOME/Downloads/$DESTINATION"
if [ -d "$SOURCE_PATH" ]; then
echo "Merging $SOURCE_PATH into $DEST_PATH"
rsync -av --ignore-existing --remove-source-files "$SOURCE_PATH/" "$DEST_PATH/"
find "$SOURCE_PATH" -type d -empty -delete
else
echo "Source folder $SOURCE_PATH does not exist. Skipping."
fi
fi
done
echo "Merge complete! All folders are now in: $DESTINATION"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment