Page 1 of 1

Script works well but freezes XYplorer after 6 iterations

Posted: 09 Jul 2023 18:14
by guimcast@gmail.com
Hi!

I made this script(go easy on me because i'm a noob), and it runs fine for a few times like 5 or 6 and then xyplorer freezes.
specs: 64gb RAM; ryzen 3900x; rtx 3090; 16TB black HD


The script does the following:
gets all files with same name until last underscore, create folder with that name and put files inside.

Each folder has around 100mb of image files.

I don't think its RAM problem, but i ran outta options. My XYplorer is up to date.

Maybe HD cache?

Is there a way to troubleshoot this problem?

Thanks!

Re: Script works well but freezes XYplorer after 6 iterations

Posted: 09 Jul 2023 19:07
by highend
That's a mess, no time to debug that...

Would this one fit your needs?

Code: Select all

    $items = <get SelectedItemsNames>;
    end ($items == ""), "Select something";
    if !(regexmatches(regexreplace($items, "\.[^.]+?$"), "[0-9]")) { end true; }

    showstatus 0;
    setting "BackgroundFileOps", 0;

    $strToFind = "_";
    while ($items) {
        $firstItem     = gettoken($items, 1, <crlf>);
        $tillStrToFind = regexmatches($firstItem, "^.+" . $strToFind . "\d+");
        $escaped       = regexreplace($tillStrToFind, "([\\^$.+()\[{])", "\$1");
        $pattern       = "^" . $escaped . ".*?";
        $matches       = regexmatches($items, $pattern . "$");
        if ($tillStrToFind) {
            moveto $tillStrToFind, $matches, , 2, 2;
            $items = regexreplace($items, $pattern . "(\r?\n|$)");
        } else {
            $items = gettoken($items, 2, <crlf>, , 2);
        }
        wait 1;
    }

Re: Script works well but freezes XYplorer after 6 iterations

Posted: 09 Jul 2023 19:52
by guimcast@gmail.com
Wow, so fast. Thank you!

But... as you can see, these are the files(for example):

cg1_asphalt_pavement_1.jpg
cg1_asphalt_pavement_1_diffuse.png
cg1_asphalt_pavement_1_glossiness.png
cg1_asphalt_pavement_1_height.png
cg1_asphalt_pavement_1_normal.png
cg1_asphalt_pavement_1_reflection.png
cg1_asphalt_pavement_2.jpg
cg1_asphalt_pavement_2_diffuse.png
cg1_asphalt_pavement_2_glossiness.png
cg1_asphalt_pavement_2_height.png
cg1_asphalt_pavement_2_normal.png
cg1_asphalt_pavement_2_reflection.png
cg1_asphalt_pavement_3.jpg
cg1_asphalt_pavement_3_diffuse.png
cg1_asphalt_pavement_3_glossiness.png
cg1_asphalt_pavement_3_height.png
cg1_asphalt_pavement_3_normal.png
cg1_asphalt_pavement_3_reflection.png

Your script created one folder (cg1_asphalt_pavement_) and move all files to it.

I actually need it to go to separate folders such as:

cg1_asphalt_pavement_1
cg1_asphalt_pavement_2
cg1_asphalt_pavement_3

Tell me if you need more info, thanks!

Re: Script works well but freezes XYplorer after 6 iterations

Posted: 09 Jul 2023 20:38
by highend
Get the code again, it now acts accordingly to your example names...

Re: Script works well but freezes XYplorer after 6 iterations

Posted: 10 Jul 2023 00:18
by guimcast@gmail.com
Thanks! Now i get it :)

I modified it a lil bit. Added possibility to search from start or from end.

Code: Select all

$items = <get SelectedItemsNames>;
end ($items == ""), "Select something";
if !(regexmatches(regexreplace($items, "\.[^.]+?$"), "[0-9]")) { end true; }

showstatus 0;
setting "BackgroundFileOps", 0;

$mode = "end"; // you can switch this to "start" to change the behavior

while ($items) {
    $firstItem     = gettoken($items, 1, <crlf>);
    if ($mode == "end") {
        $tillStrToFind = regexmatches($firstItem, "^.+_[0-9]+");
    } elseif ($mode == "start") {
        $tillStrToFind = regexmatches($firstItem, "^[^_]+");
    }
    $escaped       = regexreplace($tillStrToFind, "([\\^$.+()\[{])", "\$1");
    $pattern       = "^" . $escaped . ".*?";
    $matches       = regexmatches($items, $pattern . "$");
    if ($tillStrToFind) {
        moveto $tillStrToFind, $matches, , 2, 2;
        $items = regexreplace($items, $pattern . "(\r?\n)?");
    } else {
        $items = gettoken($items, 2, <crlf>, , 2);
    }
    wait 1;
}

Thanks again!