Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Extract each .rar in ~/Downloads into its own folder under ~/Games/Heroic/
- # Skips any _CommonRedist folders and existing game folders with the same name
- SOURCE_DIR="$HOME/Downloads"
- DEST_DIR="$HOME/Games/Heroic"
- mkdir -p "$DEST_DIR"
- # Loop through all .rar files in the source directory
- find "$SOURCE_DIR" -maxdepth 1 -type f -name "*.rar" | while read -r rarfile; do
- filename=$(basename "$rarfile")
- base_name="${filename%.rar}"
- extract_dir="$DEST_DIR/$base_name"
- # Skip if directory already exists
- if [ -d "$extract_dir" ]; then
- echo "Skipping $filename — already extracted."
- echo
- continue
- fi
- echo "Processing: $filename"
- mkdir -p "$extract_dir"
- # Extract contents while preserving structure
- unrar x -o+ "$rarfile" "$extract_dir/" >/dev/null 2>&1
- # Find and remove _CommonRedist folders if they exist
- find "$extract_dir" -type d -name "_CommonRedist" -exec rm -rf {} + 2>/dev/null
- echo "Extracted to: $extract_dir"
- echo
- done
Advertisement
Add Comment
Please, Sign In to add comment