Take this file structure:
Balls.S01.Complete/
>Balls.S01E01/
>>balls.s01e01.subs.rar
>>balls.s01e01.rar
>>balls.s01e01.r00
>>balls.s01e01.r01
>>balls.s01e01.r02
>>...
>Balls.S01E02/
>>balls.s01e02.subs.rar
>>balls.s01e02.rar
>>balls.s01e02.r00
>>balls.s01e02.r01
>>balls.s01e02.r02
>>...
>...
I wanted to create a script which extracted the file from each episode folder and moved it to the series root folder (Balls.S01.Complete).
It would do this no matter the number of episodes.
It would have a sub command line option (-s) which would decide if it would manage the subs too. If yes/true, it would move the sub file in each episode folder to an SUBPACK folder in the root directory, whether it existed or not.
I came up with this and would appreciate any input and feedback :)
#!/bin/bash #Extraction tool for series file structure with subs while getopts s opt do case "$opt" in s ) subs=true;; * ) continue;; esac done shift $[ $OPTIND - 1 ] count=1 for param in "$@" do location=$param count=$[ $count + 1 ] done if ! [ -d $location ] then echo "Directory not found" exit fi if [ subs ] then for dir in $location* do if [ -d $dir ] && [[ $dir == *SUB* ]] then subdir=$dir/ else echo No subdir found subs=false fi done fi for dir in $location* do if [ -d $dir ] && [[ $dir != *SUB* ]] then for file in $dir/* do if [[ $file == *sub* ]] && [ subs ] then mv $file $subdir elif [[ $file == *.rar ]] then rar e $file $location fi done fi done
Executed like:
filename -s ./Balls.S01.Complete/


Sign In
Create Account


Back to top









