Skip to content

Instantly share code, notes, and snippets.

@seawolf
Created October 21, 2012 10:53
Show Gist options
  • Save seawolf/3926671 to your computer and use it in GitHub Desktop.
Save seawolf/3926671 to your computer and use it in GitHub Desktop.
Extracts a RAR file after confirmation into it's own named directory in the current directory, and asks to remove the archive
#!/bin/bash
#
# extract_rar.bash
# Extracts a RAR file after confirmation into it's own named directory
# in the current directory, and asks to remove the archive
#
# Copyright (C) 2012 Ben Arnold
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# Visit http://www.gnu.org/licenses for the GNU General Public License.
OLDIFS=$IFS
IFS=$(echo -en "\n\b")
USERNAME=`whoami`
RARPATH="/home/$USERNAME/Downloads"
RAREXT="rar"
for RAR in `ls -1 $RARPATH/*.rar` ; do
echo
echo "File: $RAR"
NAME="`echo "$RAR" | sed "s#$RARPATH/##g" | sed "s#\.$RAREXT##g"`"
echo "Dir: $NAME"
unrar l "$RAR"
echo ; echo -n "Extract the above files to \"$NAME\" ? (y/n) "
read year
if [[ -n "$year" && ( "$year" == "y" || "$year" == "Y" ) ]] ; then
mkdir "$NAME"
cd "$NAME"
echo "PWD: $PWD"
unrar e "$RAR"
echo ; echo -n "Rename the above files from $RAR ? (y/n) "
read rename
if [[ -n "$rename" && ( "$rename" == "y" || "$rename" == "Y" ) ]] ; then
NEWIFS=$IFS
IFS=$OLDIFS
bash ../../number_files.bash && echo "Completed."
IFS=$NEWIFS
else
echo "Skipping."
fi
cd ..
echo ; echo -n "Remove $RAR ? (y/n) "
read remove
if [[ -n "$remove" && ( "$remove" == "y" || "$remove" == "Y" ) ]] ; then
rm $RAR && echo "Removed."
else
echo "Skipping."
fi
else
echo "Skipping."
fi
done
IFS=$OLDIFS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment