Created
January 12, 2025 01:23
-
-
Save Jan-Zeiseweis/a9314c0b9e9c12077db5184de20334fc to your computer and use it in GitHub Desktop.
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/zsh | |
# Check if the correct number of arguments is provided | |
if [[ $# -ne 2 ]]; then | |
echo "Usage: $0 <directory> <password>" | |
exit 1 | |
fi | |
# Read arguments | |
ARCHIVE_DIR="$1" | |
PASSWORD="$2" | |
# Check if the provided directory exists | |
if [[ ! -d "$ARCHIVE_DIR" ]]; then | |
echo "Error: Directory '$ARCHIVE_DIR' does not exist." | |
exit 1 | |
fi | |
# Loop through all .7z files in the directory | |
for file in "$ARCHIVE_DIR"/*.7z; do | |
if [[ -f "$file" ]]; then | |
# Extract the filename without the extension | |
base_name=$(basename "$file" .7z) | |
# Create a folder named after the archive | |
mkdir -p "$ARCHIVE_DIR/$base_name" | |
# Extract the archive into the created folder | |
7z x -p"$PASSWORD" -o"$ARCHIVE_DIR/$base_name" "$file" | |
# Check if extraction was successful | |
if [[ $? -eq 0 ]]; then | |
echo "Successfully extracted: $file to $ARCHIVE_DIR/$base_name" | |
else | |
echo "Failed to extract: $file" | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment