Move subdirectories up one level and rename

0

I'm trying to use Cygwin to re-organize my music folder. Currently it's in iTunes format

{Artist}/{Album}/Song ##.mp3

I want to copy the album folders up to the parent folder and add the artist name, so

~/{Artist}/{Album} becomes ~/{Artist} - {Album}

but I am having trouble writing a script that works. Tried this:

for i in ~/music/*; { mv $i ~/'basename - $i';}

to no avail. Any help? Thanks!

Mathletics

Posted 2010-12-28T01:51:29.437

Reputation: 101

Answers

0

try:

cd ~/music
find . -type f | while read i; do album=${i/*\//}; temp=${i/.\//}; artiste=${temp/\/*\/*/}; song=${i/.\/*\/*\//}; mkdir ~/music/$artiste"-"$album; mv $i ~/music/$artiste"-"$album/$song; done 

though i would advise to use cp first instead of mv. just in case... this script does not remove the old folders as well.

basically it reads the full path name of each file. then extract the bits like artiste name, song title and album title. it then manipulates these information to give you the directory style you want.

Reuben L.

Posted 2010-12-28T01:51:29.437

Reputation: 942

Like the other script, it's hiccuping any time there are spaces in the directory name. Also, there isn't any artist/album info in the filename, just the title and track number. However, the parent folder is always the artist and each subdirectory under that folder is always the album titles. – Mathletics – 2010-12-28T02:31:11.477

Since we have already declared the album and artist as variables, if you want the album and artiste name in the filename you can change the $song output to something like $artiste"-"$album"-"$song.

As for the space issue, perhaps you could do a quick – Reuben L. – 2010-12-28T06:02:25.390

sed to replace all the spaces in filenames with underscores. – Reuben L. – 2010-12-28T06:13:00.663