Hi,
I'm fairly new at scripting.
I need to write a script that takes files from a source directory puts them in a target directory and sorts them by artist name.
This is what I have so far
#!/bin/bash
source_dir='/home/tcindy/songs'
target_dir='/home/tcindy/music'
for path in $(grep .mp3 /home/tcindy/songs)
do
tag=$(tail -c 128 $path)
song_name=$(echo "$tag" | cut -c 4-33 | sed -r 's/ +$//')
artist=$(echo "$tag" | cut -c 34-54 | sed -r 's +$//')
album=$(echo "$tag" | cut 55-128 | sed -r 's +$//')
done
filename="$artist - $song_name.mp3"
echo $filename
if [ -n "$artist" ] && [ -n "$title" ] && [ -n "$album" ];then
filename="$track - $title - $album - $artist.mp3";echo $filename
cp "$F" "$filename" #renaming the file(copy)
if [ -d "$target_dir/$artist/$album" ];then #moving file to the artist folder
mv "$filename" "$target_dir/$artist/$album"
else
if [ -d "$target_dir/$artist" ];then
mkdir "$target_dir/$artist/$album"
mv "$filename" "$target_dir/$artist/$album"
else
mkdir "$target_dir/$artist"
mkdir "$target_dir/$artist/$album"
mv "$filename" "$target_dir/$artist/$album"
fi
fi
exit
Any help would be greatly appreciated!!