How to expand a tree folder to show direct subfolders only?

Discuss and share scripts and script files...
Post Reply
Jerry
Posts: 835
Joined: 05 May 2010 15:48
Location: The UnUnited States of America

How to expand a tree folder to show direct subfolders only?

Post by Jerry »

How can I have a script expand the currently selected folder in the Mini Tree to show just the direct subfolders under that folder and no further levels down? In other words, do the equivalent of clicking on the + control for the folder for the first time or after it's been hidden and put back into the Mini Tree.

I always use the Mini Tree and sometimes want to see all the direct subfolders under a parent folder instead of just the ones I've been visiting. So I started a script that does this, but can't find a way to do the final step.

Code: Select all

$path=tab("get", "path");
  loadtree($path, 2);  // first hide the parent folder
  loadtree($path, 1); // then, add it back into the Mini Tree
  // Next,  how to expand $path to show just immediate subfolders only?
Jerry
Running on Windows 10 Pro 64-bit quad-core ASUS G752-VY notebook with 64 GB RAM, over 26 external USB3 drives attached via multiple powered hubs with letters and mount points, totaling 120+ TB. SCREEN SCALING: 125%

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

Re: How to expand a tree folder to show direct subfolders on

Post by highend »

Too tired to think and too lazy to code atm ;)

But why don't you store a list of all current subfolders via folderreport() in a variable and load them through a foreach loop?
One of my scripts helped you out? Please donate via Paypal

Jerry
Posts: 835
Joined: 05 May 2010 15:48
Location: The UnUnited States of America

Re: How to expand a tree folder to show direct subfolders on

Post by Jerry »

highend wrote:But why don't you store a list of all current subfolders via folderreport() in a variable and load them through a foreach loop?
That approach seems awfully complicated to do a very simple thing. I'd rather see Don add an expand command with options to fully expand or only expand 1 level deep. In fact, I'm rather surprised there wasn't an existing command to do this already.

Jerry
Running on Windows 10 Pro 64-bit quad-core ASUS G752-VY notebook with 64 GB RAM, over 26 external USB3 drives attached via multiple powered hubs with letters and mount points, totaling 120+ TB. SCREEN SCALING: 125%

neutrox
Posts: 194
Joined: 05 Mar 2012 15:23

Re: How to expand a tree folder to show direct subfolders on

Post by neutrox »

this way:

Code: Select all


   $startpath = "<curpath>";
   $folders = get(selecteditemspathnames);
   foreach($folder, $folders, "<crlf>") {
   $sec = exists($folder);
   if ($sec == 2) {   }
   elseif ($sec != 2) { continue 2; }
   $subreport = folderreport("dirs", "r", "$folder", "");
   if ($subreport == "") {   }
   elseif ($subreport != "") { goto gettoken($subreport, 1, "<crlf>"); }

                                 }
Instructions:

-turn on minitree;
-select the target folders you want to see expanded or select all, the script will ignore FILES if selected;
-run the script.
I use this on regulartree and it happens to work on minitree. :P

admin
Site Admin
Posts: 66256
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: How to expand a tree folder to show direct subfolders on

Post by admin »

FYI, hold CTRL when you collapse a mini tree node by clicking on the little "minus" and it will be initialized: Next time you click the little "plus" you will see all subfolders.

Jerry
Posts: 835
Joined: 05 May 2010 15:48
Location: The UnUnited States of America

Re: How to expand a tree folder to show direct subfolders on

Post by Jerry »

admin wrote:FYI, hold CTRL when you collapse a mini tree node by clicking on the little "minus" and it will be initialized: Next time you click the little "plus" you will see all subfolders.
Ok, that will be easier than scripting, in the absence of an expandtree command. Thanks.

Jerry
Running on Windows 10 Pro 64-bit quad-core ASUS G752-VY notebook with 64 GB RAM, over 26 external USB3 drives attached via multiple powered hubs with letters and mount points, totaling 120+ TB. SCREEN SCALING: 125%

Jerry
Posts: 835
Joined: 05 May 2010 15:48
Location: The UnUnited States of America

Re: How to expand a tree folder to show direct subfolders on

Post by Jerry »

neutrox wrote:this way:

Code: Select all

   $startpath = "<curpath>";
   $folders = get(selecteditemspathnames);
   foreach($folder, $folders, "<crlf>") {
   $sec = exists($folder);
   if ($sec == 2) {   }
   elseif ($sec != 2) { continue 2; }
   $subreport = folderreport("dirs", "r", "$folder", "");
   if ($subreport == "") {   }
   elseif ($subreport != "") { goto gettoken($subreport, 1, "<crlf>"); }
                                 }
Thanks neutrox. I'll keep this script in mind for future needs. But as Don suggested, holding down Ctrl and pressing the little minus, followed by the little plus without Ctrl, is the answer for this particular problem, for me at least.

Jerry
Running on Windows 10 Pro 64-bit quad-core ASUS G752-VY notebook with 64 GB RAM, over 26 external USB3 drives attached via multiple powered hubs with letters and mount points, totaling 120+ TB. SCREEN SCALING: 125%

hermhart
Posts: 244
Joined: 13 Jan 2015 18:41

Re: How to expand a tree folder to show direct subfolders on

Post by hermhart »

Could an option under "Expansion" be added into the popup context menu you get when you right-click on a folder in the tree:

Fully Expand
Expand by level... (new option - opens a dialogue to ask how many levels deep to expand?)
Fully Collapse
-
Fully Collapse Drive
Optimize Tree
Windows 11 Pro; 100% scaling

admin
Site Admin
Posts: 66256
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: How to expand a tree folder to show direct subfolders on

Post by admin »

In theory yes, but overkill ATM.

Papoulka
Posts: 455
Joined: 13 Jul 2013 23:41

Re: How to expand a tree folder to show direct subfolders on

Post by Papoulka »

I keep trying to use Minitree but run into the same problem with not easily viewing first-level folders. Even with the Ctrl key I could never get it right.

Now I wonder if there is a bug here. Starting with a ::fresh instance, I enable Minitree and navigate to a main folder which has 50 direct folders (each with one subfolder). Then holding Ctrl down the whole time, in the Tree pane I repeatedly left-click the '+/-' symbol for this main folder. With each click the Tree pane changes, which is fine. However, it sometimes shows the 50 direct folders only, and other times shows the 50 direct folders and their subfolders i.e. expanded. Sometimes it shows the expanded view for several clicks, then after a few (or even 10) clicks switches back to direct folders only.

I thought at first that it is supposed to cycle through some sequence of presentations, but I don't see a pattern.

This is with XY v15.40.0102.

Post Reply