Created
May 15, 2017 07:57
-
-
Save rghose/ca8054f19e6d347261453d96b9713621 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Sorts songs of an FILE_TYPE and places them into appropriate folders | |
# where artist name is separated by SEPARATOR | |
# | |
# Also counts the total files copied. | |
# | |
# (C) Mirage 2017 | |
# | |
FILE_TYPE=mp3 | |
SEPARATOR=- | |
counter=0; | |
OLDPWD=`pwd`; | |
if [ ! -z "$1" ]; then | |
cd "$1"; | |
fi | |
while read song; do | |
if [ -z "$song" ]; then break; fi | |
counter=$(( counter + 1 )); | |
echo "Processing $counter. [$song]" | |
filename=$(basename "$song"); | |
artist=$(echo $filename | cut -d$SEPARATOR -f1 | awk '{$1=$1};1'); | |
if [ ! -d "$artist" ]; then | |
echo "Directory $artist does not exist. creating..." | |
mkdir "$artist"; | |
fi | |
mv "$song" "$artist"/"$filename"; | |
done < <(find . -d 1 -iname "*.$FILE_TYPE"); | |
if [ $counter -eq 0 ]; then | |
echo "No files in current directory. Usage: $0 <directory where files reside>"; | |
else | |
echo "Done copying $counter files" | |
fi | |
cd $OLDPWD; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment