You are not logged in.

#1 2009-07-11 21:39:43

julio
Member
From: São Carlos/SP, Brazil
Registered: 2009-06-10
Posts: 9
Website

[Solved] Rename multiple folders

Hi,
I was organizing my music library and found some folders like this:

1974NameOfAlbum/
2002AnotherName/

I know it's possible to rename using mv, however I don't know how to insert  "\ -\ " in the 5th character to have something like

1964 - NameOfAlbum/
2002 - AnotherName/

I guess it can be done with shellscript using rename, mv or cut. (but I don't know how sad )

Last edited by julio (2009-07-12 01:36:47)


smile

Offline

#2 2009-07-11 22:02:27

djszapi
Member
From: Cambridge, United Kingdom
Registered: 2009-06-14
Posts: 1,439
Website

Re: [Solved] Rename multiple folders

ls -1|sed -e "s/^\(.*\)hello\(.*\)$/mv '\1hello\2''\1 - hello\2'/"|bash

Something similar, it renames in the $pwd the *hello* folders to * - hello*

The problem is i don't know your rules. Is the date 4 character in every case ? It can be solved with sed easily.

Hope this helps

Offline

#3 2009-07-11 22:03:53

julio
Member
From: São Carlos/SP, Brazil
Registered: 2009-06-10
Posts: 9
Website

Re: [Solved] Rename multiple folders

Thanks for the fast answer.. I'll test now

Yes, all dates have 4 characters.


smile

Offline

#4 2009-07-12 00:45:52

julio
Member
From: São Carlos/SP, Brazil
Registered: 2009-06-10
Posts: 9
Website

Re: [Solved] Rename multiple folders

djszapi wrote:

ls -1|sed -e "s/^\(.*\)hello\(.*\)$/mv '\1hello\2''\1 - hello\2'/"|bash

Your code was just missing a space between '\1hello\2' and '\1 - hello\2'. Really helped me.

I made:

ls -1|sed -e "s/^\(....\)\(.*\)$/mv '\1\2' '\1 - \2'/"|bash

(that gets 4 chars from the start and add the ' - ' after them)

And it solved my problem.

But what if I've already started renaming the folders one by one (with mv)?
     It would turn "1964 - NameOfAlbum/" into "1964 -  - NameOfAlbum/"...

Anyway. The biggest problem is already SOLVED.

Thanks for the help.


smile

Offline

#5 2009-07-12 07:51:05

djszapi
Member
From: Cambridge, United Kingdom
Registered: 2009-06-14
Posts: 1,439
Website

Re: [Solved] Rename multiple folders

You can do it with for;done;do cycle too, but i like sed very very much tongue
No problem.

Offline

Board footer

Powered by FluxBB