#1 2021-03-03 03:46

luisxv2k
Member
Registered: 2019-10-16
Posts: 5

How to move the final part of the file name to a position at the begin

Hi all!
I´m back!

I have the code bellow that remove duplicate text in file name as showed in examples bellow that was solved in another topic.

The code is ok and functional until this moment. Thanks for your precious help again!

var
  t1,t2,t3:WideString;
  amount:Integer;

begin
  amount:=7;
  //WideCopy(String, Index, Count) Syntax
  t1 := WideCopy(FileName,1,amount);        //Copy first  7: Start from pos 1, take 7
  t2 := WideCopy(FileName,amount+1,amount); //Copy second 7: Start from pos 8, take 7
  t3 := WideCopy(FileName,amount+1,999);    //Copy wanted name: Start from pos 8, take till the end
  If(t1=t2) Then FileName := t3;
end.

Example A: From
SBBI - SBBI - ADC.pdf
SBBP - SBBP - VAC.pdf
SBBQ - SBBQ - ADC.pdf
SBBR - SBBR - ADC.pdf
SBBV - SBBV - PDC.pdf
SBCA - SBCA - VAC.pdf

Exemplo B: To
SBBI - ADC.pdf
SBBP - VAC.pdf
SBBQ - ADC.pdf
SBBR - ADC.pdf
SBBV - PDC.pdf
SBCA - VAC.pdf

But now, at last, I have another need.
I´m need to move the last 7 characters before extension of the file name to position 5 of the same filename and to reach the final desired results.

Examples:
From:
    SBSP - BUVGU.1A - RWY 17L - 17R - XSID.pdf
    SBSP - CPN.1B - RWY 17L - 17R - STAR.pdf
    SBSP - IAC - RNAV - GNSS - S - RWY 17L - XIAC.pdf

To:
    SBSP - XSID - BUVGU.1A - RWY 17L - 17R.pdf
    SBSP - STAR - CPN.1B - RWY 17L - 17R.pdf
    SBSP - XIAC - IAC - RNAV - GNSS - S - RWY 17L.pdf

Question: What is the best line of code to implement this new need?

Thank you again!

Offline

#2 2021-03-03 16:09

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

Re: How to move the final part of the file name to a position at the begin

The new problem can be solved more elegantly with a Regular Expressions rule:

> Replace expression "\A(.+?) - (.+) - (.+?)\Z" with "$1 - $3 - $2" (skip extension)

The old problem can also be solved more elegantly with a Regular Expressions rule:

> Replace expression "\A(.+?) - \1 - (.+)\Z" with "$1 - $2" (skip extension)

Both rules use the " - " delimiter to identify the needed parts.

For the reference:
https://www.den4b.com/wiki/ReNamer:Regular_Expressions

Offline

#3 2021-03-03 20:47

luisxv2k
Member
Registered: 2019-10-16
Posts: 5

Re: How to move the final part of the file name to a position at the begin

Hi,
I definitely convince myself that I have to learn how these Regular Expressions work, and without a doubt they work excellently!
Thank you again!
One more problem solved!

Offline

Board footer

Powered by FluxBB