Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- LOC=$(dirname $(realpath $0))
- LIST=$LOC/downloaded
- OUTDIR=$LOC/../Sorted
- [ ! -d "$1" ] && exit 1;
- dir=$1
- dir=${dir%%/}
- dirs=( 0 $( cat $LIST | cut -d';' -f3 | grep -v "n/a" | sort | uniq ) )
- IFS=$'\n'
- files=($dir/*)
- for file in ${files[*]}; do
- # get the name of the module from the 7z archive
- if [ ${file: -3} == .7z ]; then
- name=$(7z l -slt $file | grep Path | tail -1)
- name=${name##*= }
- name=${name##*/}
- else
- name=$file
- fi
- # find the genre of the file
- genre=($(grep $name $LIST | cut -d';' -f3 | grep -v "n/a"))
- if [[ ${#genre[@]} -eq 1 ]]; then
- file2=$( basename $file )
- [ ! -d "$OUTDIR/${genre[0]}" ] && mkdir "$OUTDIR/${genre[0]}"
- mv -iv "$file" "$OUTDIR/${genre[0]}/$file2"
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement