modern_lisp-machine/misc/scripts/decompress_7z.sh

43 lines
1.2 KiB
Bash
Executable File

EXEC_SHELL_PATH=$(command -v bash)
# Ensure that 7z and unrar are installed
if ! command -v 7z >/dev/null 2>&1 || ! command -v unrar >/dev/null 2>&1; then
echo "Error: 7z or unrar not found. Please install 7z and unrar before running this script."
exit 1
fi
# Function to create directory with Unicode compatibility and strip file extension
create_directory() {
directory_name=$(basename "$1" | sed -E 's/\.(7z|zip|rar)$//' | iconv -t utf-8)
mkdir -p "$directory_name"
}
# Function to extract 7z and zip files
extract_7z_zip() {
7z x "$1" -o"$PWD/$directory_name"
}
# Function to extract rar files
extract_rar() {
unrar x "$1" "$PWD/$directory_name"
}
# Loop through each compressed file in the current folder
for compressed_file in *.7z *.zip *.rar; do
# Create a directory for the compressed file
create_directory "$compressed_file"
# Determine which extraction function to call based on file extension
case "$compressed_file" in
*.7z | *.zip)
extract_7z_zip "$compressed_file"
;;
*.rar)
extract_rar "$compressed_file"
;;
esac
done
echo "Extraction completed successfully."