You are not logged in.
Hi den4b and Team!
I have a folder with several subfolders and within the subfolders several files with different names.
I need to rename files that have the first 7 positions equal to the next 7 positions.
Example:
A file named "SBAC - SBAC - ADC.pdf" should be renamed to "SBAC - ADC.pdf".
A file named "SBBE - SBBE - PDC.pdf" should be renamed to "SBBE - PDC.pdf".
How to solve it?
Thanks for your support!
Admin note: Your post was moved from topic #2107. No necroposting, as per forum rules.
Last edited by den4b (2019-10-16 19:19)
Offline
Hi and welcome luisxv2k.
Your issue (rename if double start at name begin) is different from the issue in this topic (rename from file content), so these posts may be moved to a new dedicated thread.
- - -
FROM:
ABBA - SBBE - PDC.pdf
SBAC - SBAC - ADC.pdf < doubled part 'SBAC - '
SBBE - SBBE - PDC.pdf
YEAR - SBAC - ADC.pdf
TO:
ABBA - SBBE - PDC.pdf
SBAC - ADC.pdf < doubled part removed
SBBE - PDC.pdf
YEAR - SBAC - ADC.pdf
TRY this
PascalScript (see http://www.den4b.com/wiki/ReNamer:Rules:PascalScript)
var
t1,t2,t3:WideString;
amount:Integer;
begin
amount:=7;
//WideCopy(String, Index, Count)
t1 := WideCopy(FileName,1,amount); //first 7: start from pos 1, take 7
t2 := WideCopy(FileName,amount+1,amount); //second 7: start from pos 8, take 7
t3 := WideCopy(FileName,amount+1,999); //wanted name: start from pos 8, take till the end
//ShowMessage( t1 +#13+ t2 +#13+ t3);
If(t1=t2) Then FileName := t3;
end.
HTH?
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
Hi Stefan,
Thank you so much for the quick return!
I applied this code to the files and it worked perfectly!
Thank you again!
Offline
You can also use the power of back references in the Regular Expressions rule, like follows:
Replace expression "(\w+)\s+\-\s+\1" with "$1" (skip extension)
Example input:
SBBI - SBBI - ADC.pdf
SBBP - SBBP - VAC.pdf
SBBQ - SBBQ - ADC.pdf
SBBR - SBBR - ADC.pdf
SBBV - SBBV - PDC.pdf
SBCA - SBCA - VAC.pdf
Output:
SBBI - ADC.pdf
SBBP - VAC.pdf
SBBQ - ADC.pdf
SBBR - ADC.pdf
SBBV - PDC.pdf
SBCA - VAC.pdf
Offline
You can also use the power of back references in the Regular Expressions rule
Thank you, I tried that at first, but failed on the syntax. Good to know that this way works also.
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