Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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!

share|improve this question
add comment

1 Answer

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.

share|improve this answer
    
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 Dec 28 '10 at 2:31
    
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. Dec 28 '10 at 6:02
    
sed to replace all the spaces in filenames with underscores. –  Reuben L. Dec 28 '10 at 6:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.