#1 2020-11-03 11:42

Hans
Member
Registered: 2020-11-03
Posts: 4

Move date-part to end of filename

Hi,

First of all: thanks for this outstanding tool!

I've been searching through the forum, have seen some examples / look-alikes, but probably my case is too different (?)
Goal is to move a 'date'-part to the end of the filename. Problem is that the files differ from the total number of 'parts'

I count the file-parts by space, so after each space there is a new part in the filename (right?)

Example of files:
XYZ - 2019-01-02 - abc def ghij klm nop.ext
>> to me, this file has 9 parts (dashes included).

XYZ - 2020-11-22 - abc def ghij klmnopq.ext
>> this file has 8 parts.

XYZ - 2020-01-01 - abc def.ext
>> this one has 6 parts.


The (only) thing what the files have in common, is that the date-part, is part 3. And that all files start with XYZ -
And as I said, after this date-part, the amount of the following file-parts differ.

Output should then be this:
XYZ - abc def ghij klm nop 2019-01-02.ext
XYZ - abc def ghij klmnopq 2020-11-22.ext
XYZ - abc def 2020-01-01.ext

Last edited by Hans (2020-11-03 11:42)

Offline

#2 2020-11-03 18:10

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

Re: Move date-part to end of filename

There are few different ways for achieving what you want, with varying levels of complexity and flexibility.

Based on your examples, the easier way is to use the Rearrange rule, but using " - " as a delimiter rather than a space.

* Split using: Exact pattern of delimiters
* Delimiters: " - | - "  (without quotes)
* New pattern: "$1 - $3 $2"  (without quotes)

A more complex alternative is the Regular Expressions, but it also ensures that the middle part looks like a date:

* Expression: "\A(.+?)[\s\-]+(\d+-\d+-\d+)[\s\-]+(.+?)\Z"  (without quotes)
* Replace: "$1 - $3 $2"  (without quotes)

Input files:

XYZ - 2019-01-02 - abc def ghij klm nop.ext
XYZ - 2020-11-22 - abc def ghij klmnopq.ext
XYZ - 2020-01-01 - abc def.ext

Output files (with either of the rules above):

XYZ - abc def ghij klm nop 2019-01-02.ext
XYZ - abc def ghij klmnopq 2020-11-22.ext
XYZ - abc def 2020-01-01.ext

Offline

#3 2020-11-05 09:30

Hans
Member
Registered: 2020-11-03
Posts: 4

Re: Move date-part to end of filename

Thank you very much for this solution - it works perfect!

I used the Regular Expressions-alternative and now I'm trying to understand both the formulas: what is causing the 'behaviour' so that (despite of the different amounts of filename-parts) the date-part gets moved to the end of the filename? Is it the (.+?)
How does it know what the end is / where the end is? This because the filenames differ in filename-parts/amounts.

And another question:
In the Replace-section, the $-signs represent the filenameparts, right? So, $3 is the date-part. What is "$3 $2" doing in the replace part, what is it's function?

Thanks again for your help!

Last edited by Hans (2020-11-05 11:02)

Offline

#4 2020-11-05 11:01

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

Re: Move date-part to end of filename

Expression:

\A(.+?)[\s\-]+(\d+-\d+-\d+)[\s\-]+(.+?)\Z

Main components of the expression:

\A  — start of filename.
\Z  — end of filename.
.+  — one or more of any characters.
[\s\-]+  — one or more space or dash characters.
\d+  — one or more digits.
(...)  — grouping to allow reuse via $1, $2, $3 and so on.

The groups used in the expression:

$1 — part before the date.
$2 — the date part.
$3 — part after the date.

Then, the replacement pattern "$1 - $3 $2" simply moves them around.

More info on the Regular Expression::
https://www.den4b.com/wiki/ReNamer:Regular_Expressions

Offline

Board footer

Powered by FluxBB