35 lines
795 B
Bash
35 lines
795 B
Bash
|
EXEC_SHELL_PATH=$(command -v bash)
|
||
|
|
||
|
|
||
|
# Check if a folder path is provided as an argument
|
||
|
if [ "$#" -eq 0 ]; then
|
||
|
echo "Usage: $0 <folder_path>"
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
# Get the folder path from the command line
|
||
|
folder_path="$1"
|
||
|
|
||
|
# Change to the specified folder
|
||
|
cd "$folder_path" || exit 1
|
||
|
|
||
|
# Loop through each file in the folder
|
||
|
for file in *.{rar,zip,7z}; do
|
||
|
# Check if the file exists
|
||
|
if [ -e "$file" ]; then
|
||
|
# Remove the file extension to create the directory name
|
||
|
dir_name="${file%.*}"
|
||
|
|
||
|
# Create the directory if it doesn't exist
|
||
|
mkdir -p "$dir_name"
|
||
|
|
||
|
# Use the appropriate tool to extract the file
|
||
|
case "$file" in
|
||
|
*.rar) unar -o "$dir_name" "$file" ;;
|
||
|
*.zip | *.7z) 7z x -o"$dir_name" "$file" ;;
|
||
|
esac
|
||
|
|
||
|
echo "Extracted $file to $dir_name/"
|
||
|
fi
|
||
|
done
|