rearranging file name

A swapping-ground for Regular Expression syntax

rearranging file name

Postby Daphne Eze » Sat Nov 10, 2018 8:52 pm

I have file names with this pattern
BER CEN ENG 1851 William

I want to change it to this
BER CEN ENG William 1851

How would I do this?

Thank you.
Daphne
Daphne Eze
 
Posts: 5
Joined: Sat Nov 10, 2018 8:41 pm

Re: rearranging file name

Postby Admin » Sun Nov 11, 2018 10:44 am

Hi,

are all the files always having the same structure, i.e. 5 parts separated by space and need to switch the last 2 parts?
Can you post a few examples of names from -> to ?

thanks
Admin
Site Admin
 
Posts: 2343
Joined: Tue Mar 08, 2005 8:39 pm

Re: rearranging file name

Postby Daphne Eze » Sun Nov 11, 2018 8:12 pm

yes
Daphne Eze
 
Posts: 5
Joined: Sat Nov 10, 2018 8:41 pm

Re: rearranging file name

Postby Daphne Eze » Sun Nov 11, 2018 8:37 pm

From
BER CEN ENG 1851 William

To
BER CEN ENG William 1851

From
BER CEN US 1930 Harold

To
BER CEN US Harold 1930
Daphne Eze
 
Posts: 5
Joined: Sat Nov 10, 2018 8:41 pm

Re: rearranging file name

Postby Admin » Mon Nov 12, 2018 1:30 am

Try Match:

([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*)

Replace:

\1 \2 \3 \5 \4
Admin
Site Admin
 
Posts: 2343
Joined: Tue Mar 08, 2005 8:39 pm

Re: rearranging file name

Postby Daphne Eze » Mon Nov 12, 2018 7:58 pm

Thank you so much. That worked perfectly.

I would like to make sure that I understand this -
Each section ([^ ]*) refers to any characters that are not a space.

The space between the groups starts another group.
Is this correct?

([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*)

\1 is contents of Group 1 etc.
by putting \5 before \4 group 5 replaces group 4
and
group 4 replaces group 5

\1 \2 \3 \5 \4
Daphne Eze
 
Posts: 5
Joined: Sat Nov 10, 2018 8:41 pm

Re: rearranging file name

Postby Admin » Tue Nov 13, 2018 12:31 am

Yes, correct, each ([^ ]*) matches a string of characters but excluding space. In between each there are spaces.
Once matched the first will be \1, the second \2 and so on until \5.
We then reorder them in the replace with a space in between.
Admin
Site Admin
 
Posts: 2343
Joined: Tue Mar 08, 2005 8:39 pm

Re: rearranging file name

Postby Daphne Eze » Tue Nov 13, 2018 10:49 pm

Thank you so much for your help.
Daphne Eze
 
Posts: 5
Joined: Sat Nov 10, 2018 8:41 pm

Re: rearranging file name

Postby Bruno5 » Wed Apr 17, 2019 11:43 pm

I have a large number of files, all with just the date as filename, but the filename is in the format MMDDYY, so april 18 2019 is written as: 041819
This is of course not so good, because the files do not arrange in a chronological way.
Is there an easy way to change all the files into a format of YYMMDD, so that it becomes 190418 ?
That would be much better.
Thank you very much
Bruno5
 
Posts: 2
Joined: Wed Apr 17, 2019 11:06 pm

Re: rearranging file name

Postby therube » Thu Apr 18, 2019 12:40 am

(Without looking...)


1:RegEx
Code: Select all
Match:  (\d\d)(\d\d)(\d\d)
Replace:  \3\1\2



Where I sit, it's still 190417 ;-).

Depending on the range of your dates, you might run into "conflicts".
If so, Renaming Options -> Prevent Duplicates might help out.
therube
 
Posts: 1314
Joined: Mon Jan 18, 2016 6:23 pm

Re: rearranging file name

Postby Bruno5 » Thu Apr 18, 2019 3:31 pm

Wow it really worked! :D :D :D :D :D
More than one thousand files are now renamed and in chronological order.
Thank you so much!
Bruno5
 
Posts: 2
Joined: Wed Apr 17, 2019 11:06 pm


Return to Regular Expressions


cron