You are not logged in.

#1 2009-05-27 14:20:12

janga
Member
Registered: 2007-12-01
Posts: 4

[SOLVED] batch renaming folders into folder/subfolder

Hi guys.

I have a huge mp3-collection on my Archlinux server.
Folder structure of my music folder is as follows:

1994 - Guided By Voices - Bee Thousand 
1994 - Helmet - Betty 
1994 - House Of Pain - Same As It Ever Was

Each of the album folders contains of course the mp3s and cover art.
Now i want to mass rename/move the folders to this pattern:

Guided By Voices/1994 - Guided By Voices - Bee Thousand 
Helmet/1994 - Helmet - Betty 
House Of Pain/1994 - House Of Pain - Same As It Ever Was

So its a pretty simple task, from "%1 - %2 - %3" to "%2/%1 - %2 - %3"
But i failed so far. Can you help?

Last edited by janga (2009-05-27 15:03:22)

Offline

#2 2009-05-27 14:37:14

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] batch renaming folders into folder/subfolder

It should be simple w/ awk, have you tried it?
If you're not emotionally connected to spaces, please, consider deleting them and / or switching to underscores, like that: '_'.

Offline

#3 2009-05-27 14:43:42

janga
Member
Registered: 2007-12-01
Posts: 4

Re: [SOLVED] batch renaming folders into folder/subfolder

I have not tried awk or sed yet, mainly because i am not a programmer, but a linux noob with little experience.
I need a newbie-friendly solution, like "do this and that".
And yes, i like space.:D

Oh and i tried mmv so far.

Last edited by janga (2009-05-27 14:45:37)

Offline

#4 2009-05-27 14:45:21

dmartins
Member
Registered: 2006-09-23
Posts: 360

Re: [SOLVED] batch renaming folders into folder/subfolder

easytag might be able to do this for you.. the interface isn't the most intuitive but once you figure it out, it can be pretty powerful.

Offline

#5 2009-05-27 14:48:41

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] batch renaming folders into folder/subfolder

And yes, i like space.big_smile

And this will be your downfall ... ;-)
I can try writing a script for you but:
- you'll have to wait half a day,
- I'm a noob myself, so I'm not responsible for anything bad that might happen (the house on fire, your wife leaves you etc.). When you're trying sth out it's best to run in in a sandbox, f.e. copy some music and run the script on that copy, see if you like the output.

Offline

#6 2009-05-27 14:51:20

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: [SOLVED] batch renaming folders into folder/subfolder

You can get the second part with cut, and trailing/leading spaces can be removed with a simple echo.

for file in *; do
[ -d "$file" ] || continue
dir=$(echo $(echo "$file" | cut -s -d- -f2))
[ -z "$dir" ] && continue
mkdir "$dir"
mv "$file" "$dir"
done

EDIT: Error: exit should be continue! Added -s for cut and the -z test.

Last edited by Procyon (2009-05-27 14:57:01)

Offline

#7 2009-05-27 14:55:40

janga
Member
Registered: 2007-12-01
Posts: 4

Re: [SOLVED] batch renaming folders into folder/subfolder

karol, i have already made a testing dir (and i´m not married).
dmartins, i know easytag, but i´d rather work myself into awk than trying to understand this horrible GUI.

Offline

#8 2009-05-27 15:02:49

janga
Member
Registered: 2007-12-01
Posts: 4

Re: [SOLVED] batch renaming folders into folder/subfolder

Woohoo! Procyon, it worked! Many thanks man. To all of you. Great distro, great community.

Offline

#9 2009-05-27 15:09:01

perbh
Member
From: Republic of Texas
Registered: 2005-03-04
Posts: 765

Re: [SOLVED] batch renaming folders into folder/subfolder

It's only horrible because you use spaces!
The unix/linux command line interpreter (ie the 'shell') splits a string into 'tokens' where each token is seperated by one or more blanks/tabs. Then it operates on these tokens.

When you use spaces you will have to do some acrobatics to make it work, eg: you have a file called 'old file' and you want to copy it to 'newfile'

 cp old file newfile

will _not_ work as you anticipate, but

 cp "old file" newfile

will do the needfull

[edit]
Spaces will cause you problems - sooner or later (unless you live in the M$-world) - your best bet would be to realize that straightaway and do away with them - use '-' or '_' instead.
[/edit]

Last edited by perbh (2009-05-27 15:11:42)

Offline

Board footer

Powered by FluxBB