From f8105e816d155d89a296172452bf8f6098ad6ea7 Mon Sep 17 00:00:00 2001 From: tianyu Date: Wed, 29 Oct 2014 21:14:31 +0800 Subject: [PATCH] Update r2t.sh --- r2t.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/r2t.sh b/r2t.sh index 31bb4b6..3b1d707 100644 --- a/r2t.sh +++ b/r2t.sh @@ -1,10 +1,10 @@ #!/bin/bash -#title :z2t +#title :r2t #description :This script will convert all rars(of jpg/bmp/png) with any content struct to tars(of jpg). Use "convert" command to convert images to jpg to depress disk space. the origin file's content struct will not change. #author :xdtianyu@gmail.com #date :20141029 #version :1.0 final -#usage :bash z2t +#usage :bash r2t #bash_version :4.3.11(1)-release #============================================================================== @@ -79,8 +79,10 @@ for file in *.rar ; do tmpdir=$(mktemp -d) DIR="${file%%.rar*}" echo "unrar x $file $tmpdir"; - unrar x "$file" $tmpdir # unrar to a tmp directory. - + mv "$file" tmp.rar + unrar x tmp.rar $tmpdir # unrar to a tmp directory. + mv tmp.rar "$file" + if [ $(ls $tmpdir | wc -l) = 1 ]; then # check if has folders, and mv the unrared directory as same name with the rar file. DIR2=$(ls $tmpdir) mv "$tmpdir/$DIR2" "$DIR"