Page 1 of 1

[Solved] Filter last Items in every Folder

Posted: 22 Dec 2024 06:17
by oebyaq
Hello,
I've a folder that have hundreds of subfolders, each subfolder contain tons of images (numeric serial)
viewing in branch mode I can easily show only the first image in every folder by using the live filter to filter all images with "001", however I can't do the same if I need to show only the the last image in every folder
is this is possible with XYplorer?

Re: Filter last Items in every Folder

Posted: 22 Dec 2024 07:06
by highend
Via scripting? Kind of

- Put the script on a keyboard shortcut (at least that's what I would recommend).
- Be in branch view
- Run the script, you should now be in a paperfolder view
Now add the path column to this view and save your settings!
- Run the script again, it will redisplay the last branch view

Code: Select all

    // Switch between an existing branch view into a
    // paperfolder with only the last img file and back

    // D:\!Tests\view? /flat
    // paper:Last image per folder
    perm $P_BV_Path;

    $view = tab("get", "term");
    if (strpos($view, "?") != -1) {
        $type      = "bv";
        $P_BV_Path = gettoken($view, 1, "?", "t");
    }
    elseif (strpos($view, "paper:") != -1) { $type = "pf"; }

    setting "BackgroundFileOps", 0;

    // Switch to pf
    if ($type == "bv") {
        $subs = quicksearch("/types={:image} /p", $P_BV_Path, , "s");

        // Last item(s)
        $last = "";
        foreach($sub, $subs, <crlf>, "e") {
            $files  = quicksearch("/types={:image}", $sub);
            $last  .= gettoken($files, -1, <crlf>) . <crlf>;
        }
        if ($last) { paperfolder("Last image per folder", $last); }

    // Switch to bv
    } elseif ($type == "pf") {
        if ($P_BV_Path) {
            goto $P_BV_Path;
            #311;
            $P_BV_Path = "";
        }
    }

Re: Filter last Items in every Folder

Posted: 22 Dec 2024 07:28
by oebyaq
That works! thank you :)
is it possible to just filter the files or do this without saving as a paper folder? in particular the part about writing the images list to the disk (the paper folder in the app dir)

Re: Filter last Items in every Folder

Posted: 22 Dec 2024 08:08
by highend
Using filters to remove _all_ non wanted pictures (maybe thousands?) from the list, possible, but I won't do it.

You can use a virtual folder view instead but to add the path column to it, you need to save your column layout (once) before you use the script.

So:
Setup your column layout, make sure the path column is added
Execute this from the address bar:
columnlayout("vi - last images", "save");

Then again, make sure you're in branch view, execute the script to switch back and forth

Code: Select all

    perm $P_BV_Path;

    $layout = "vi - last images";
    $view   = tab("get", "term");
    if (strpos($view, "?") != -1) {
        $type      = "bv";
        $P_BV_Path = gettoken($view, 1, "?", "t");
    }
    elseif (strpos($view, "vi:") != -1) { $type = "vi"; }

    setting "BackgroundFileOps", 0;

    // Switch to vi
    if ($type == "bv") {
        $subs = quicksearch("/types={:image} /p", $P_BV_Path, , "s");

        // Last item(s)
        $last = "";
        foreach($sub, $subs, <crlf>, "e") {
            $files  = quicksearch("/types={:image}", $sub);
            $last  .= gettoken($files, -1, <crlf>) . <crlf>;
        }
        if ($last) {
            goto "vi:" . $last;
            columnlayout("vi - last images");
        }

    // Switch to bv
    } elseif ($type == "vi") {
        if ($P_BV_Path) {

            goto $P_BV_Path;
            #311;
            $P_BV_Path = "";
        }
    }

Re: Filter last Items in every Folder

Posted: 22 Dec 2024 08:45
by oebyaq
Well, as long as the images list isn't saved to disk it works.
Thank you very much!
This is exactly what I'm looking for : )