find Duplicate based on first 'n' characters

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
skehg
Posts: 15
Joined: 20 May 2018 05:33

find Duplicate based on first 'n' characters

Post 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

highend
Posts: 14956
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: find Duplicate based on first 'n' characters

Post by highend »

Sure, but this can only be done via scripting...
One of my scripts helped you out? Please donate via Paypal

RalphM
Posts: 2090
Joined: 27 Jan 2005 23:38
Location: Cairns, Australia

Re: find Duplicate based on first 'n' characters

Post 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.
Ralph :)
(OS: W11 25H2 Home x64 - XY: Current x64 beta - Office 2024 64-bit - Display: 1920x1080 @ 125%)

skehg
Posts: 15
Joined: 20 May 2018 05:33

Re: find Duplicate based on first 'n' characters

Post 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?

highend
Posts: 14956
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: find Duplicate based on first 'n' characters

Post by highend »

If you want to move them, instead of preselecting the "earlier" versions, add that yourself...
Find dupes by first 12 characters.xys
To see the attached files, you need to log into the forum.
One of my scripts helped you out? Please donate via Paypal

skehg
Posts: 15
Joined: 20 May 2018 05:33

Re: find Duplicate based on first 'n' characters

Post 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.

skehg
Posts: 15
Joined: 20 May 2018 05:33

Re: find Duplicate based on first 'n' characters

Post 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...";
    }

yusef88
Posts: 1148
Joined: 28 Jan 2013 03:50
Location: Windows 8.1 32-bit

Re: find Duplicate based on first 'n' characters

Post 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

Post Reply