moving part of filename to another location

A swapping-ground for Regular Expression syntax

moving part of filename to another location

Postby Diego020 » Wed Nov 09, 2016 7:34 pm

i have a folder filled with music albums, named like this:

Artist - Title [quality][year]
Aalon - Cream City [320KBPS][1977]

for sorting options i would like to move the year portion of the filename to another location:

Artist - year - Title [quality]
Aalon - 1977 - Cream City [320KBPS]

i have been trying this myself but i dont have sufficiënt knowledge of regex, can someone help me out?
Diego020
 
Posts: 4
Joined: Wed Nov 09, 2016 7:29 pm

Re: moving part of filename to another location

Postby KenP » Wed Nov 09, 2016 8:00 pm

This should do it.

RegEx (1)
Match: ^(.*- )(.*)\[(\d{4})
Replace: \1\3 - \2
KenP
 
Posts: 198
Joined: Sat Jul 30, 2016 11:25 am

Re: moving part of filename to another location

Postby Diego020 » Wed Nov 09, 2016 8:07 pm

almost there!

when using that code it returns this folder name

Aalon1977Cream City [320KBPS]

so its missing " - " in front and after the year
Diego020
 
Posts: 4
Joined: Wed Nov 09, 2016 7:29 pm

Re: moving part of filename to another location

Postby KenP » Wed Nov 09, 2016 8:21 pm

That's strange because it works for me :?

Did you copy/paste the code ?
KenP
 
Posts: 198
Joined: Sat Jul 30, 2016 11:25 am

Re: moving part of filename to another location

Postby Diego020 » Wed Nov 09, 2016 8:44 pm

got it! another replace action was also active that was causing the problem.

thanks alot!

if its not too much trouble could you explain the different parts of the code so i can understand it better?
Diego020
 
Posts: 4
Joined: Wed Nov 09, 2016 7:29 pm

Re: moving part of filename to another location

Postby KenP » Wed Nov 09, 2016 9:57 pm

Diego020 wrote:if its not too much trouble could you explain the different parts of the code so i can understand it better?


Artist - Title [quality][year]


RegEx (1)
Match: ^(.*- )(.*)\[(\d{4})
Replace: \1\3 - \2

Match:
^ : Denotes the start of the string.
(.*- ) This is the first group Group 1, the .*- matches any character or space any number of times up-to and including the - (hyphen followed by a space)

(.*) This is the second group Group 2, the .* matches any character or space any number of times.

\[ This stops group 2 from matching anything after and including the first square bracket, this is not grouped because it's not needed in the replace.

(\d{4}) This is the last group Group 3 and matches the date, the \d catches a digit and the {4} tells the regex engine to catch the previous character 4 times, so \d{4} matches 4 digits.


In the Replace box, to use a group you write the group number preceded with a back-slash so group 1 is \1.

Replace:
First in the replace box we have \1 which is group 1 (Artist).
Second we have \3 which is group 3 (the 4 digits that make up the year).
Third we have - (space hyphen space), this is the space hyphen space after the year.
Lastly is \2 which is group 2, this is the Title and Quality.

Basically it's just a matter of breaking the entire file name into reusable groups (groups are in parenthesis and numbered according to their position in the regex), then placing those groups in the replace box in the order you want them, you can place literal characters in-between the groups, for instance group 3 is followed by space hyphen space then group 2 (\3 - \2).
KenP
 
Posts: 198
Joined: Sat Jul 30, 2016 11:25 am

Re: moving part of filename to another location

Postby Diego020 » Fri Nov 11, 2016 2:28 pm

@KenP

thank you so much!
you are amazing for taking the time to help me out.

this helps me alot in understanding how to use regex in the app.

thanks again!
Diego020
 
Posts: 4
Joined: Wed Nov 09, 2016 7:29 pm

Re: moving part of filename to another location

Postby RussV » Sat Jan 21, 2017 11:43 am

Hi KenP

Sorry, I am very new at this. I have read and tried the above but am unable to get it to work, possibly because of the "_"'s in my file names.

I am trying to move the date in this file name DJI_A01857_C003_20160915_000015.dng to this new position DJI_A01857_20160915_C003_000015.dng

There are any number of these files, each representing a frame of a video sequence and they are in a folder which has the same name, but excludes the last 6 digits that represent the video frame.

Much like this:
Folder: DJI_A01857_C003_20160915
Files: DJI_A01857_C003_20160915_000000.dng
DJI_A01857_C003_20160915_000001.dng
DJI_A01857_C003_20160915_000002.dng
etc.
Is there a way of renaming the folder and all the files in the same way, at the same time?

To this...
Folder: DJI_A01857_20160915_C003
Files: DJI_A01857_20160915_C003_000000.dng
DJI_A01857_20160915_C003_000001.dng
DJI_A01857_20160915_C003_000002.dng
etc.
Any assistance would be greatly appreciated.

Regards
Russ
RussV
 
Posts: 2
Joined: Sat Jan 21, 2017 11:10 am

Re: moving part of filename to another location

Postby KenP » Sat Jan 21, 2017 12:58 pm

@ RussV

This should do what you want.

In the folder tree view on the left select the directory that the folder or folders is in.

Filters (12)
Mask: DJI_A01857* (If you're trying to rename more than one folder you'll need to do them 1 at a time and use whatever works to filter the required folder)
Subfolders: checked

RegEx (1)
Match: ([^_]*_)([^_]*)_([^_]*)(_)(\d{8})(.*)
Replace: \1\2\4\5_\3\6
KenP
 
Posts: 198
Joined: Sat Jul 30, 2016 11:25 am

Re: moving part of filename to another location

Postby RussV » Sat Jan 21, 2017 2:31 pm

Thank you so much KenP

That worked like a charm. I am very grateful for your assistance.

Regards
RussV
RussV
 
Posts: 2
Joined: Sat Jan 21, 2017 11:10 am

Re: moving part of filename to another location

Postby pebbleridge » Sun Feb 05, 2017 2:42 pm

Hi Guys,

I need your help please, I'm rubbish at this stuff.

My music files are in one directory in the format:-

artist name - track name.mp3

All I want to do is swap them arround so I get:-

track name - artist name.mp3

I've installed Bulk Rename Utility and downloaded and read the full manual and I am no wiser.

I've been reading the forums and I see people offering solutions like :-

RegEx (1)
Match: ^(.*- )(.*)\[(\d{4})
Replace: \1\3 - \2


But I can't even figure out what I should do with it.

Is there any hope for me?

Regards,

Paul
pebbleridge
 
Posts: 2
Joined: Sun Feb 05, 2017 1:44 pm

Re: moving part of filename to another location

Postby KenP » Sun Feb 05, 2017 2:55 pm

@ pebbleridge

The RegEx example that you've posted is completely wrong for what you're trying to do :wink:

1. With BRU open browse to and select the folder that holds the music files.

2. In the RegEx (1) box copy and paste the following tokens.
Match: (.*) - (.*)
Paste: \2 - \1

3. In the main window select the files that you want to rename.

4. Check that the files names are correct in the "New Name" column.

5. Press the Rename button.
KenP
 
Posts: 198
Joined: Sat Jul 30, 2016 11:25 am

Re: moving part of filename to another location

Postby pebbleridge » Sun Feb 05, 2017 4:27 pm

Hi KenP,

Many thanks for your quick reply, (I only gave the example as the "type" of information posters were giving) :oops:

I did what you said, but I couldn't find Paste: so I put \2 - \1 into Replace and It worked.

I can now do my changes many thanks.

Regards,

Paul
pebbleridge
 
Posts: 2
Joined: Sun Feb 05, 2017 1:44 pm

Re: moving part of filename to another location

Postby KenP » Sun Feb 05, 2017 4:33 pm

pebbleridge wrote:Hi KenP,

Many thanks for your quick reply, (I only gave the example as the "type" of information posters were giving) :oops:

I did what you said, but I couldn't find Paste: so I put \2 - \1 into Replace and It worked.

I can now do my changes many thanks.

Regards,

Paul

Oops that's a typo, "Paste" should have read "Replace" :oops:

Anyway I'm glad you got it sorted :wink:
KenP
 
Posts: 198
Joined: Sat Jul 30, 2016 11:25 am


Return to Regular Expressions