Page 1 of 1
find Duplicate based on first 'n' characters
Posted: 24 Oct 2022 02:42
by skehg
Is there a way to find or filter files if the first 'n' characters of their file names match?
e.g. I have may files in the same folder (called current pdf's) and everytime I issue new files they get revised and copied into the the folder. The files below show an example of what would give a match if the first 12 characters match. I then want to delete [F] revision file and keep the [G] revision file.
9119-S-01-05 [F] FOOTING AND SLAB ON GROUND PLAN - SECTOR 05.pdf
9119-S-01-05 [G] FOOTING AND SLAB ON GROUND PLAN - SECTOR 05.pdf
Re: find Duplicate based on first 'n' characters
Posted: 24 Oct 2022 03:53
by highend
Sure, but this can only be done via scripting...
Re: find Duplicate based on first 'n' characters
Posted: 24 Oct 2022 07:49
by RalphM
highend is right for full automation but if you still want some manual control, you could just live filter the list with the first 'n' characters and then delete the 'F' version manually.
Re: find Duplicate based on first 'n' characters
Posted: 24 Oct 2022 09:00
by skehg
Thanks for the feedback. I think filter will by first 'n' characters will give me a list of all files still eg a really simple file list would look like this
9119-S-00-01 [F] FOOTING AND SLAB ON GROUND PLAN - SECTOR 01.pdf
9119-S-00-02 [3] FOOTING AND SLAB ON GROUND PLAN - SECTOR 02.pdf
9119-S-00-02 [4] FOOTING AND SLAB ON GROUND PLAN - SECTOR 02.pdf
9119-S-01-03 [F] FOOTING AND SLAB ON GROUND PLAN - SECTOR 03.pdf
9119-S-01-04 [G] FOOTING AND SLAB ON GROUND PLAN - SECTOR 04.pdf
9119-S-01-05 [F] FOOTING AND SLAB ON GROUND PLAN - SECTOR 05.pdf
9119-S-01-05 [G] FOOTING AND SLAB ON GROUND PLAN - SECTOR 05.pdf
In this case, I would expect the filter to return
9119-S-00-02 [3] FOOTING AND SLAB ON GROUND PLAN - SECTOR 02.pdf
9119-S-00-02 [4] FOOTING AND SLAB ON GROUND PLAN - SECTOR 02.pdf
9119-S-01-05 [F] FOOTING AND SLAB ON GROUND PLAN - SECTOR 05.pdf
9119-S-01-05 [G] FOOTING AND SLAB ON GROUND PLAN - SECTOR 05.pdf
or I would want a script to move the following to a superseded folder
9119-S-00-02 [3] FOOTING AND SLAB ON GROUND PLAN - SECTOR 02.pdf
9119-S-01-05 [F] FOOTING AND SLAB ON GROUND PLAN - SECTOR 05.pdf
any suggestions for a filter that would do that?
Re: find Duplicate based on first 'n' characters
Posted: 24 Oct 2022 10:05
by highend
If you want to move them, instead of preselecting the "earlier" versions, add that yourself...
Find dupes by first 12 characters.xys
Re: find Duplicate based on first 'n' characters
Posted: 24 Oct 2022 13:05
by skehg
Thats great thanks highend. The paper folder didn't seem to return anything so I commented that out and it is selecting all the duplicates I want to move to the superseded folder which is perfect thank you.
Re: find Duplicate based on first 'n' characters
Posted: 25 Oct 2022 06:19
by skehg
For any interested, this is the script I ended up with. A big thanks to @highend
Code: Select all
$files = formatlist(listfolder(, , 1+4, <crlf>), "n", <crlf>);
$dupes = "";
$toSel = "";
$chars = 12;
while (true) {
if (!$files) { break; }
$file = gettoken($files, 1, <crlf>);
$start = substr($file, 0, $chars);
$esc = regexreplace($start, "([\\^$.+()\[{])", "\$1");
$match = regexmatches($files, "^" . $esc . ".+?(?=\r?\n|$)", <crlf>);
$cntMatch = gettoken($match, "count", <crlf>);
if ($cntMatch > 1) {
$toSel .= gettoken($match, $cntMatch - 1, <crlf>, , 1) . <crlf>;
$dupes .= $match . <crlf>;
$files = regexreplace($files, "^" . $esc . ".+?(\r?\n|$)");
} else {
$files = gettoken($files, 2, <crlf>, , 2);
}
}
if ($dupes) {
moveto "SUPERSEDED", $toSel, , 2, 1, 5, 1, 1, 1, , 0, 1;
} else {
text "No duplicate(s) found...";
}
Re: find Duplicate based on first 'n' characters
Posted: 25 Oct 2022 10:04
by yusef88
skehg wrote: ↑24 Oct 2022 13:05
The paper folder didn't seem to return anything so
paper folder returns the name of dupes not the full path