dd_mmm_yyyy > yymmdd : regex and replace

A swapping-ground for Regular Expression syntax

Re: dd_mmm_yyyy > yymmdd : regex and replace

Postby ckjian » Sat Nov 22, 2008 3:48 am

jimwillsher wrote:I'd probably do them in two phases. I'm assuming they don't all have Nov, some are Oct etc? In which case, use the Character Translations option:

J,a,n=0,1
F,e,b=0,2
...
N,o,v=1,1
D,e,c=1,2


etc.


Then handle the ".1" becoming "1." as a separate task. You can easily do the two in the same move of course, but no sense clouding the issues if it's a one-off task you have.


Jim


Thank Jim, I got it.

spotburst wrote:Hi ckjian,

In total your renaming will look like this:

In the main BRU window: Match (KN)(.*)(200)(.*)\.(.*)
Replace \5\1\20\4

If you highlight your file in the file lister old 'Name' to 'New name' will appear as:
KN21Nov2008.1.pdf 1KN21Nov08.pdf

you can see that the bracketed terms in the match string become fields-to-use in the replace string
ie.
1. (KN) is field 1, it matches the KN in your filename >> in the replace string \1 references the string KN
2. the first (.*) is field 2,it matches the 21Nov in your filename >> in the replace string \2 references the string 21Nov
3. (200) is field 3 or 200 >> you will not use this when you rebuild in the replace string (if you wanted to it would be \3)
4. the next (.*) is field 4, it matches 8 in your filename >> in the replace string \4 references the string 8
5. \. matches .
6. the next (.*) is filed 5, it matches your 'kind of siffixed' 1 >> in the replace string \5 references the string 1

so the replace string \5\1\20\4 catenates all of your wanted fields (and other literla bits-and-bobs) thus:
field 5 + field 1 + field 2 + 0 (literally) + field 4 = 1KN21Nov08.pdf

Now for the character translation (which I was originally having problems with):

Choose 'Options' drop-down in the main menu
Choose 'Character Translation' (or Ctrl+F6 if you like)
In the empty table that appears you need to enter:
J,a,n=0,1
F,e,b=0,2
M,a,r=0,3
A,p,r=0,4
etc.

This will the translate the 'Nov' in your 1KN21Nov08.pdf string to '11' yielding your desired result: 1KN211108.pdf

Hope this helps.


Thank you for your input spotburst. I'm still new to this software so I need some time to digest your instruction :D

Oh ya. Actually there is another pattern that I missed out. That is actually the 3 pad count on the page number.

E.g.
KN21Nov2008.1.pdf --> 001KN21Nov08.pdf
KN21Nov2008.11.pdf --> 011KN21Nov08.pdf
KN21Nov2008.111.pdf --> 111KN21Nov08.pdf

Any idea how to include the pad count?

Looks like my file renaming task can be done using this software. It saves me a tedious work for renaming 1k+ files.

Thank again

EDIT: Text formatting and add in more examples
ckjian
 
Posts: 5
Joined: Fri Nov 21, 2008 8:57 am

Re: dd_mmm_yyyy > yymmdd : regex and replace

Postby ckjian » Sat Nov 22, 2008 10:06 am

I got everything renamed already. Thank you so much for all your help. Really appreciate it.

I did the pad count by using Character Translations option:

1,K,N=0,0,1,K,N
1,1,K,N=0,1,1,K,N
...

There are only 30+ pages for each date. Therefore, I'm alright to create additional 30+ character translations. However, please let me know if there is a better way to do this.

Thank again.
ckjian
 
Posts: 5
Joined: Fri Nov 21, 2008 8:57 am

Re: dd_mmm_yyyy > yymmdd : regex and replace

Postby GMA » Sun Nov 23, 2008 12:26 am

Hi, ckjian:
Sure; you can use the following four steps:

Step 1 - Renaming all files with one number at the end (E.g. "KN21Nov2008.1.pdf"):
RegEx (1):
MATCH: (KN)(.*)(20)(..)(\.)(.)$
REPLACE: 00\6\1\2\4

Step 2 - Renaming all files with two numbers at the end (E.g. "KN21Nov2008.23.pdf"):
RegEx (1):
MATCH: (KN)(.*)(20)(..)(\.)(..)$
REPLACE: 0\6\1\2\4

Step 3 - Renaming all files with three numbers at the end (E.g. "KN21Nov2008.456.pdf"):
RegEx (1):
MATCH: (KN)(.*)(20)(..)(\.)(...)$
REPLACE: \6\1\2\4

Step 4 - The second phase described by spotburst:
"Options > Character Translation":
J,a,n=0,1
F,e,b=0,2
M,a,r=0,3
A,p,r=0,4
etc.

Hope that helps.

Gabriel.
GMA
 
Posts: 91
Joined: Sun Dec 02, 2007 1:30 pm
Location: Argentina

Re: dd_mmm_yyyy > yymmdd : regex and replace

Postby GMA » Sun Nov 23, 2008 12:44 am

By the way, and this is just my humble opinion, the format you're using seems a little problematic to me, at least if you don't have your files divided in a number of subfolders, like year, month and day. I mean, it'll be difficult to find specific file/s if there's no logic sorting. For example, when sorted by name, they'll look like this:

001KN211108.pdf
002KN150109.pdf
002KN220708.pdf
003KN190408.pdf
...


See how mixed up they are, considering their dates? Extend that to 1000+ of files and obviously it'll be quite hard to quickly spot one of them in your file browser (and sorting them by creation/modification date is not always reliable; many times you end up with modified dates when burning files to a CD and then copying them back to a HD; or when sharing files via Internet/LAN, or when compressing/extracting, etc.).
Again, just my opinion, but maybe you should look for a format that allows a proper sorting by name, such as

KN_[Year][Month][Day]_[Additional numbering].pdf

Which results in (using the same examples from above):

KN_080419_003.pdf
KN_080722_002.pdf
KN_081121_001.pdf
KN_090115_002.pdf
...


Anyway, just a thought :wink:. Best regards,

Gabriel.
GMA
 
Posts: 91
Joined: Sun Dec 02, 2007 1:30 pm
Location: Argentina

Previous

Return to Regular Expressions