[Bash] Auto create CDx/DVDx directories (for those who don't auto unrar)

Come up with a useful post-processing script? Share it here!
Post Reply
Mills
Newbie
Newbie
Posts: 11
Joined: August 19th, 2009, 7:02 pm

[Bash] Auto create CDx/DVDx directories (for those who don't auto unrar)

Post by Mills »

I'm not really a bash scripter, I just adopted ideas from other's scripts (thanks SceneSort guy).

If you can improve it, please feel free to post a better revision and I'll update the post.

Code: Select all

count=0
index=1
cd $1

for file in *.sfv; do
        let count+=1
done

if [ $count -gt 1 ]; then
        for file in *.sfv; do
                total_filesize=0
                basename=`echo $file | head -c -5`
                for rarfile in $basename*; do
                        [ -f "$rarfile" ] || continue
                        filesize=$(stat -c %s "$rarfile")
                        ((total_filesize += filesize))
                done
                if [ $total_filesize -lt 744488960 ]; then # 710MB
                        media="CD"
                else
                        media="DVD"
                fi
                if [ -f "$file" ]; then
                        if [ ! -d $media$index ]; then
                                mkdir -v $media$index
                        fi
                        mv -v $basename* $media$index
                fi
                let index+=1
        done
fi
Probably best run after you move subs, not sure how to handle when other sfvs are included with games like updates.

Disclaimer: I make no guarantees that this code will work or that it will not harm your data, your machine, your family, or anything else.

Mills
Last edited by Mills on August 27th, 2009, 2:13 am, edited 1 time in total.
Post Reply