#1 2020-04-26 08:51

koolestani
Member
Registered: 2020-04-26
Posts: 9

How to bring Date "component" to the front/beginning of file name?

Hi
I have 2 "types" of file names that need this treatment, maybe even more that i'm not yet aware of:

  1. aaaa.bb.YY.MM.DD.ccc.txt

  2. aaaa.YY.MM.DD.bbb.cc.txt

I tried using the the Rearrange rule with the following settings
imgur.com/fwj6aVn
imgur.com/XzSpl4c

As you can see it works for type 1 but not for type 2

imgur.com/V0Hhqfk
imgur.com/bCrQ4Uo

As you can see it works for type 2 but not for type 1

Similarly if i discover more types, the rule will need tweaking for those too.
What I want to achieve here is to bring the Date component of the file name to the beginning. Eg:
YY.MM.DD.aaaa.bb.ccc.txt
The delimiter for all the files is period, that much is known.
There are hundreds of files of each type, so carefully selecting each type and treating them separately is inconvenient to say the least.

The closest I got to make the software understand that I'm interested in manipulating the Date component was through Reg Ex (thanks to Wiki)

\b(\d{2}).(\d{2}).(\d{2})\b

But this expression only allows me to rearrange the parts of the Date itself and the not the manner in which the preceding and succeeding parts will be rearranged

I have tried my best to find out if this query has already been answered before posting this. I have referred the Wiki and still not able to figure out how to achieve this.

Any help is appreciated.

Last edited by koolestani (2020-04-26 08:57)

Offline

#2 2020-04-26 09:22

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,440

Re: How to bring Date "component" to the front/beginning of file name?

You were actually quite close with the RegEx, well done!

The following pattern should work in all cases:

Replace expression "\A(.*?)\.*\b(\d{2})\.(\d{2})\.(\d{2})\b\.*(.*?)\Z" with "$2.$3.$4.$1.$5" (skip extension)

Some hints about the different components do:

\A – Start of the subject
\Z – End of the subject
.*? – Matches a sequence of any characters, in non-greedy mode.
\. – Matches an actual dot (dot alone is a magic character that matches any character).
\.* – Matches any number of actual dots, zero or more.
\d{2} – Matches exactly 2 digits.
\b – Word boundary (a break between a word and a non-word character).

You probably found the user manual already, but here it is just in case:
https://www.den4b.com/wiki/ReNamer:Regular_Expressions

Offline

#3 2020-04-26 10:26

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: How to bring Date "component" to the front/beginning of file name?

Me would think we can make that expression looks a little bit more simply:


FROM:
20.04.26.aa.bb.ccc.txt
aaaa.bb.20.04.26.ccc.txt
aaaa.bb.2020.04.26.ccc.txt
aaaa.20.04.26.bbb.cc.txt
aaaa.bb.ccc.20.04.26.ddd.txt
aaaa.bbccdd.20.04.26.txt

TO:
20.04.26.aa.bb.ccc.txt
20.04.26.aaaa.bb.ccc.txt
20.04.26.aaaa.bb.ccc.ddd.txt
20.04.26.aaaa.bbb.cc.txt
20.04.26.aaaa.bbccdd..txt
2020.04.26.aaaa.bb.ccc.txt


USE:
RegEx rule: Replace expression "(.+?)\.(\d{2,4}\.\d{2}\.\d{2})\.?(.*)" with "$2.$1.$3" (skip extension)
https://www.den4b.com/wiki/ReNamer:Rules:RegEx


Explanation:
Match
(.+?) >> one-or-more(+) of everything non-greedy(?) and store in group $1 for later reuse.
\. >>>>> single literal dot before the date, do not store, drop it.
(\d{2,4}\.\d{2}\.\d{2}) >>> two to four digits, dot, and so on... to match an date yy.mm.dd or yyyy.mm.dd > store in group $2
\.? >>> none-or-one(?) trailing dot, if any (if date is at the end of the file name).
(.*) >>> none-or-more(*) of everything till the end > store in group $3
https://www.den4b.com/wiki/ReNamer:Regular_Expressions




Nothing wrong, just another view.
Advantage of den4bs' expression is, you can rearrange the order of the single date parts (ymd) too, if wanted.
ReNamer is much more powerful as one might think.

 


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#4 2020-04-26 13:29

koolestani
Member
Registered: 2020-04-26
Posts: 9

Re: How to bring Date "component" to the front/beginning of file name?

Wow!
Thanks for the fast response. Both the methods are spot on.
I really need to learn some Reg Ex, since I am still having a hard time thinking about the possibilities hidden behind it.

I don't want to be a bother, but just in case I think of going back to the original naming scheme, can you devise a way to "shift" this Date component after say; the second period in the file name?
What would the expression look like if it had to be shifted to the third period in the file name?
And lastly if it had to shifted to the end of the file name.

Offline

#5 2020-04-26 19:45

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: How to bring Date "component" to the front/beginning of file name?

>>>"shift" this Date component after say; the second period in the file name?

Something like that?

FROM:
20.04.26.aa.bb.ccc.txt
TO:
aa.bb.20.04.26.ccc.txt

- match the date > (\d{2,4}\.\d{2}\.\d{2}) >> store as $1
- match but drop first dot after date
- match everything not-an-dot one-or-more times till second dot after date non-greedy > ([^.]+?\.)>> $2
- match not-an-dot one-or-more times till third dot > store as $3
- match the rest till end > store as  $4

Reorder the matched parts as second and third match, insert first match (the date) and add the rest matched in store $4

RegEx rule: Replace expression "(\d{2,4}\.\d{2}\.\d{2})\.([^.]+?\.)([^.]+?\.)(.*)" with "$2$3$1.$4" (skip extension)




Some help:

Parts of any RegEx pattern can be enclosed in brackets (), called a "subexpression".
Resulting matches of an subexpression are stored internally for backreference, counted from the left each opening bracket.
In the replacement, the expressions $1 through $9 represent the actual text that matches the respective subexpressions.
In other words: stored subexpression can be accessed and reused by utilizing $1, $2,... and so on.


See https://www.den4b.com/wiki/ReNamer:Regular_Expressions   for an explanation of the tokens.
Next modify the expression and the replacement order until you see some sense in all of this ;-)
Make use of the [Preview] before actual renaming.
Also utilize the "Analyze sample text" option, see http://www.den4b.com/wiki/ReNamer:Options_menu


More questions? Just ask ;-)


 


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#6 2020-04-27 10:12

koolestani
Member
Registered: 2020-04-26
Posts: 9

Re: How to bring Date "component" to the front/beginning of file name?

Thank you very much.
This answers all the possible scenarios that I asked about earlier.

Last edited by koolestani (2020-04-27 10:12)

Offline

Board footer

Powered by FluxBB