popupmenu - Add nested submenus

Discuss and share scripts and script files...
Japistos
Posts: 3
Joined: 11 Nov 2019 13:08

popupmenu - Add nested submenus

Post by Japistos »

Hi Guys, first post here.
Thank you for the amazing forums and software.

I'm really new to scripting, as you'll see by my question.

I want a popupmenu that has a top level and then sub levels that get populated by the script iterating through a folder and returning all the subfolders as menus. Then within that sub menu is a copyto command using that same token.

I've tried hacking together copy pasted bits that I can find from the help menu and from here, but my knowledge of the syntax isn't enough.

I'm not sure how to use the popupmenu and foreach loops together.

Thanks in advance.

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Foreach into popupmenu

Post by highend »

A while loop makes more sense here to check if an entry has submenus or not...

Code: Select all

    $iconFolder  = ":showfolders";
    $iconCommand = ":copyto";

    $selectedItems = <get SelectedItemsPathNames |>;
    end (!$selectedItems), "No item(s) selected, aborted!";

    $folders = quicksearch("/d /excl=$RECYCLE.BIN;System Volume Information", , , "s");
    $folders = replace($folders, "<curpath>\");

    $menu       = "";
    $indent     = <space 4>;
    $lastFolder = "";

    while ($folders) {
        $folder    = gettoken($folders, 1, <crlf>);
        $folders   = gettoken($folders, 2, <crlf>, , 2);
        $cntIndent = gettoken($folder, "count", "\") - 1;

        if ($folder != $lastFolder) {
            $indentation = strrepeat($indent, $cntIndent);
            $caption     = gpc($folder, "component", -1);
            $menu       .= <crlf> . $indentation . "$caption<:><:>$iconFolder";
        }

        if (strpos($folders, $folder) != 0) {
            $indentation = strrepeat($indent, $cntIndent + 1);
            $data  = "copyto " . quote("<curpath>\$folder") . ", " . quote($selectedItems) . ", , 2, 2;";
            $menu .= <crlf> . $indentation . "Copy <selected items> here...<:>$data<:>$iconCommand";
        }
        $lastFolder = $folder;
    }
    $selection = popupnested($menu, 6:=<crlf>, 7:="<:>");
    if ($selection) { load $selection, , "s"; }
One of my scripts helped you out? Please donate via Paypal

klownboy
Posts: 4109
Joined: 28 Feb 2012 19:27

Re: Foreach into popupmenu

Post by klownboy »

Hey highend. You should change the title on this thread so others know what it actually does (e.g., Folder submenu operations or similar). Right now no one would have a clue unless they looked through the thread.

The OP hadn't yet responded so I figured I would. :) The script works nicely. It was easy enough to modify the script to add additional submenus for "Move to" along with the "Copy to" and a couple of fixed folder locations just to provide more flexibility.
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: popupmenu - Add nested submenus

Post by highend »

Title changed
The OP hadn't yet responded so
Actually he wasn't ever online again. This is more or less an existing user who was (as always) too lazy to achieve something on his own...
One of my scripts helped you out? Please donate via Paypal

Japistos
Posts: 3
Joined: 11 Nov 2019 13:08

Re: popupmenu - Add nested submenus

Post by Japistos »

who was (as always) too lazy to achieve something on his own...
Haha, little harsh?
I agree, I should have said thank you or given feedback a little earlier... but I definitely wasn't too lazy to achieve this on my own.
Truth is, I'm not one to ask to be spoonfed without trying to figure out things on my own first.
Thank you for your reply.
So I got as far as using your code and then getting stuck again and I haven't had time to ask for more help or look at it further.

The example you provided is almost what I need, but I would like it to only go "one level down."
So basically, I point the script to a parent folder, and it just lists the immediate sub folders, not further down than that.
I think I tried to use folder report instead of quicksearch because I couldn't figure out how to limit it to one child level.
Got it to list just the subfolders I wanted, but then got stuck at something else.
Will confirm and provide more info in the morning when it's in front of me.

Thanks for the title name change, better.

klownboy
Posts: 4109
Joined: 28 Feb 2012 19:27

Re: popupmenu - Add nested submenus

Post by klownboy »

If you only want to see the immediate subfolders (1 level), change the SC quicksearch line to read as follows:
$folders = quicksearch("/d /maxdepth=0 /excl=$RECYCLE.BIN;System Volume Information", , , "s");
That should do what you want.
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

Japistos
Posts: 3
Joined: 11 Nov 2019 13:08

Re: popupmenu - Add nested submenus

Post by Japistos »

klownboy, thank you for your response! :beer:

Gabrielle
Posts: 57
Joined: 28 Apr 2012 00:57

Re: popupmenu - Add nested submenus

Post by Gabrielle »

Can I please have a version of this which would list for target all folders from panes 1 (and 2, if it's dual pane) as well as a 3 options submenu as for copy, backup and move? Thanks.

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: popupmenu - Add nested submenus

Post by highend »

for target all folders from panes 1 (and 2, if it's dual pane)
You mean the path of the existing tabs?
One of my scripts helped you out? Please donate via Paypal

Gabrielle
Posts: 57
Joined: 28 Apr 2012 00:57

Re: popupmenu - Add nested submenus

Post by Gabrielle »

Yes!

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: popupmenu - Add nested submenus

Post by highend »

Copyto, moveto, backupto to tab folders.xys
(1.88 KiB) Downloaded 109 times
One of my scripts helped you out? Please donate via Paypal

Gabrielle
Posts: 57
Joined: 28 Apr 2012 00:57

Re: popupmenu - Add nested submenus

Post by Gabrielle »

Tested! Works! Thanks! :appl:

Kenbol
Posts: 16
Joined: 23 Sep 2021 04:44

Re: popupmenu - Add nested submenus

Post by Kenbol »

Can it be like this?
Attachments
Paste Here with Path.png
Paste Here with Path.png (3.91 KiB) Viewed 2579 times

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: popupmenu - Add nested submenus

Post by highend »

One of my scripts helped you out? Please donate via Paypal

Kenbol
Posts: 16
Joined: 23 Sep 2021 04:44

Re: popupmenu - Add nested submenus

Post by Kenbol »

Thank you. I saw the flags and looked up the help file.
$data = $root. " " . quote($tmpFolder) . ", " . quote($selectedItems) . ",0 , 2, 2;";

Post Reply