Last active
September 23, 2025 18:58
-
-
Save rflpazini/7360605e2978974005fe3667541f0cc0 to your computer and use it in GitHub Desktop.
Unzip script used to extract .zip files from a folder at once
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 | |
# --- Smart Script to Unzip Files --- | |
# 1. Initial setup to find the script's own location. | |
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) | |
SOURCE_FOLDER="$SCRIPT_DIR/../ISO" | |
# Check if the source directory exists. | |
if [ ! -d "$SOURCE_FOLDER" ]; then | |
echo "Error: Directory '$SOURCE_FOLDER' not found. π" | |
exit 1 | |
fi | |
# 2. Find all .zip files and store them in an array. | |
# This allows us to count them before processing. | |
mapfile -d '' files < <(find "$SOURCE_FOLDER" -maxdepth 1 -type f -name "*.zip" -print0) | |
total_files=${#files[@]} | |
# Exit if no zip files were found. | |
if [ "$total_files" -eq 0 ]; then | |
echo "No .zip files found in '$SOURCE_FOLDER'." | |
exit 0 | |
fi | |
# 3. Print the initial "to-do" list. | |
echo "Files to Unzip:" | |
for zipfile in "${files[@]}"; do | |
echo " [ ] $(basename "$zipfile")" | |
done | |
# 4. Move the terminal cursor up to the start of the list we just printed. | |
# 'tput cuu' means "cursor up". | |
tput cuu "$total_files" | |
# 5. Process each file and update its line in the list. | |
for zipfile in "${files[@]}"; do | |
output_dir="${zipfile%.zip}" | |
mkdir -p "$output_dir" | |
# Unzip the file silently to avoid cluttering the visual list. | |
unzip -oq "$zipfile" -d "$output_dir" > /dev/null 2>&1 | |
# 'tput el' clears the current line from the cursor to the end. | |
# The 'echo' then overwrites '[ ]' with 'β ' and moves the cursor down one line. | |
tput el | |
echo " β $(basename "$zipfile")" | |
done | |
echo "---" | |
echo "All files processed successfully! π" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment