Unzip/unrar multiple files with file-specific folders

Hi,

if you want to unzip/unrar multiple files in a directory, but want to create a special folder for each content, you can use the following bash-code.

#!/bin/bash

IFS='
'

# ZIP files
for i in `ls *zip`; do
        DIRNAME=${i%.zip}

        mkdir $DIRNAME
        cd $DIRNAME
        unzip ../$i
        cd ..
done

# RAR files
for i in `ls *rar`; do
        DIRNAME=${i%.rar}

        mkdir $DIRNAME
        cd $DIRNAME
        rar x ../$i
        cd ..
done

Bye Sven