Organizing Files

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!!

Hi ,post a sample list of your source files.

  1. You can't post links untill you have at least 5 posts.
  2. Your image shows that you seem to study at Senecac. Seems a lot of students from there are visiting this site lately. Maybe get in contact with them for help.
  3. On that note: Homework has to be posted in a special forum, using special rules. See this example on how to do it, which is incidentally from a student apparently in the same course with the same problem.