Hello,
I need to generate partial file name(Meter No) from full file name.
I able to do this in Ms Office Excel, need to do the same in xyplorer via script.
Example Scenario:
D_3304711_08042021153020.XML to 3304711
03_2017341_19042021_095157.XML to 2017341
30055094_20122019235900.xml to 30055094
0001_1210344_20210419_125458_187.xml to 1210344
2358530_210421_111135.XML to 2358530
Excel Formula:
=IF((LEN(A2)-LEN(SUBSTITUTE(A2,"D_",""))),SUBSTITUTE(MID(SUBSTITUTE("_"&A2&REPT(" ",6),"_",REPT(",",255)),2*255,255),",",""),IF((LEN(A2)-LEN(SUBSTITUTE(A2,"03_",""))),SUBSTITUTE(MID(SUBSTITUTE("_"&A2&REPT(" ",6),"_",REPT(",",255)),2*255,255),",",""),IF((LEN(A2)-LEN(SUBSTITUTE(A2,"0001_",""))),SUBSTITUTE(MID(SUBSTITUTE("_"&A2&REPT(" ",6),"_",REPT(",",255)),2*255,255),",",""),IF((LEN(A2)-LEN(SUBSTITUTE(A2,"_",""))),TRIM(LEFT(A2,SEARCH("_",A2)-1)),TRIM(LEFT(A2,SEARCH("2021",A2)-1))))))
Filename Example Download Link:
https://we.tl/t-B6x3RncMYH
Thanks In Advance!
Custome Column With Partial File Name via Script
Re: Custome Column With Partial File Name via Script
TLDR;
In other words:
If the string begins with
D_
03_
0001_
use the following token, otherwise the first?
In other words:
If the string begins with
D_
03_
0001_
use the following token, otherwise the first?
Code: Select all
$base = gpc(<cc_item>, "base");
if (regexmatches($base, "^(d|03|0001)_")) { return gettoken($base, 2, "_", "t"); }
return gettoken($base, 1, "_", "t");
One of my scripts helped you out? Please donate via Paypal
Re: Custome Column With Partial File Name via Script
Your script works like a charm.
I missed to add one filename scenario:
Need file name before 2021
RSE4655420210402090132982.XML to RSE46554
500720820210404093514.xml to 5007208
Is it possible to copy this custom column file names and also highlight duplicates file name in custom column.
Thank You.
Last edited by kudou on 22 Apr 2021 05:24, edited 1 time in total.
Re: Custome Column With Partial File Name via Script
Then add that new rule?
Copy to clipboard
Select duplicates (I won't highlight them via tagging because you would need to remove them at some point afterwards)
Code: Select all
$base = gpc(<cc_item>, "base");
if (regexmatches($base, "^(d|03|0001)_")) {
return gettoken($base, 2, "_", "t");
} elseif (regexmatches($base, "2021")) {
return gettoken($base, 1, "2021", "t");
}
return gettoken($base, 1, "_", "t");
Code: Select all
$ccCaption = "Test"; // Change this to the name of your cc column
$ccNames = report("{$ccCaption}<crlf>", 1); // Switch it to 0 for all names (not only the selected ones)
copytext $ccNames;
Code: Select all
$ccCaption = "Test"; // Change this to the name of your cc column
$ccNames = report("{$ccCaption}|{fullname}<crlf>", 0);
$ccNames = formatlist($ccNames, "en", <crlf>);
$duplicates = "";
while (true) {
if (!$ccNames) { break; }
$item = gettoken($ccNames, 1, <crlf>);
$ccPart = gettoken($item, 1, "|");
$matches = regexmatches($ccNames, "^$ccPart\|.+?$", <crlf>);
if (gettoken($matches, "count", <crlf>) >= 2) {
// Remove first item from it (that's the "original")
$highlights = gettoken($matches, 2, <crlf>, , 2);
$duplicates .= regexreplace($highlights, "^.+\|") . <crlf>;
}
// Remove from our current list to process
$ccNames = formatlist($ccNames, "F", <crlf>, "!" . $matches);
}
if ($duplicates) {
$duplicates = trim($duplicates, <crlf>);
selectitems $duplicates;
}
One of my scripts helped you out? Please donate via Paypal
Re: Custome Column With Partial File Name via Script
Thanks Highend you saved my day!
One problem with filename generating
When there is no "Hyphen" in filename need the meter no before 2021
For this
60080420210402094347.xml to 600804
This is need to be
4437322_MR124_22_BILL_2021_04_01_15_44_05_602f78e26693075cec13e0d1_020421_065013.OUT.XML to 4437322
4437322_MR124_22_BILL_2021_04_01_15_44_05_602f78e26693075cec13e0d1_030421_221018.OUT.XML to 4437322
10185734_MR124_22_BILL_2021_04_01_15_59_47_602f78e06693075cec13e091_020421_214316.OUT.XML to 10185734
Thank You!
One problem with filename generating
When there is no "Hyphen" in filename need the meter no before 2021
For this
60080420210402094347.xml to 600804
This is need to be
4437322_MR124_22_BILL_2021_04_01_15_44_05_602f78e26693075cec13e0d1_020421_065013.OUT.XML to 4437322
4437322_MR124_22_BILL_2021_04_01_15_44_05_602f78e26693075cec13e0d1_030421_221018.OUT.XML to 4437322
10185734_MR124_22_BILL_2021_04_01_15_59_47_602f78e06693075cec13e091_020421_214316.OUT.XML to 10185734
Thank You!
- Attachments
-
- Clipboard-20210422-01.png (191.76 KiB) Viewed 514 times
Re: Custome Column With Partial File Name via Script
That was already covered60080420210402094347.xml to 600804
Code: Select all
$base = gpc(<cc_item>, "base");
if (regexmatches($base, "^(d|03|0001)_")) {
return gettoken($base, 2, "_", "t");
} elseif (strpos($base, "_MR124_") != -1) {
return gettoken($base, 1, "_", "t");
} elseif (strpos($base, "2021") != -1) {
return gettoken($base, 1, "2021", "t");
}
return gettoken($base, 1, "_", "t");
One of my scripts helped you out? Please donate via Paypal
Re: Custome Column With Partial File Name via Script
Thanks Highend!
Its Working Now.
Its Working Now.
- Attachments
-
- Clipboard-20210422-02.png (197.11 KiB) Viewed 505 times
Last edited by kudou on 22 Apr 2021 09:37, edited 1 time in total.