Expand Folders Command

Expand Folders is a script command for Directory Opus, which simplifies the expansion/collapse of entire branches in all or selected folders when using Expandable Folders feature in the current file display.
Its main features are:

  • Expand all folders in the current file display to their maximum depth (all levels).
  • Expand only selected folders.
  • Expand only top level folders.
  • Expand all/selected up to the desired level.
  • Collapse all/selected expanded folders.
  • Smart choice for decide between expand or collapse.
  • Optionally when expanding folders, select files/folders within.

How To Install

Download the file below. Then run Prefs SCRIPTINSTALL and select the downloaded file.
:warning: IMPORTANT: Needs at least v13.5.1

v1.6.0 : ExpandFolders.opusscriptinstall

Usage

You can use Expand Folders as a command, using ExpandFolders.
When used this way, it will expand the selected folders to their maximum depth. If no folders are selected, all folders in the current file display are used.

In addition, the command has the following arguments:

COMMAND ARGUMENTS

Argument Type Values Description
ALL /S (no value) Use all folders in the current file display. If not especified, when there's no items selected, `ALL` will be implicit.
COLLAPSE /O (no value) Collapse folders if they are expanded. Can be used in conjunction with ALL.
When used alone, selecting files will collapse the parent folder above. If folders are selected, they will be collapsed, if possible.
parent Use COLLAPSE=parent to change the difference between files and folders, and selecting subfolders will collapse their parent folders.
EXPAND /O(no value) This argument will be the default unless COLLAPSE or TOGGLE are present.
Use it to expand all or only selected folders.
int Where int is a integer referring to a level. Use EXPAND=int (eg. EXPAND=2) to expand till the desired level.
top Use EXPAND=top to only expand the first level.
SELECT /O (no value) Select all items beneath folders expanded by this command.
dirs Select dirs only, excluding the files.
TOGGLE /O (no value) Toggle between the two states, based on the expanded condition for the selected items (or all if nothing selected or ALL is used).
expandtop Use TOGGLE=expandtop to only expand the first level, if TOGGLE follows that direction.
colparent Use TOGGLE=colparent to enable parent argument when collapsing, if TOGGLE follows that direction.
int Use TOGGLE=int to refer the number of levels to expand, if TOGGLE follows that direction.

Examples

Expand all/selected folders in current file display
ExpandFolders or ExpandFolders EXPAND
Expand Folders.dcf (345 Bytes)

Expand all folders in current file display
ExpandFolders EXPAND ALL

Expand all folders to first level in current file display
ExpandFolders EXPAND=top ALL

Collapse all expanded folders in current file display
ExpandFolders COLLAPSE ALL
Collapse All Folders.dcf (343 Bytes)

Toggle expanded state for all/selected items
ExpandFolders TOGGLE

Toggle expanded state for all/selected items. If expanded, expand up to 3 levels and select only folders within
ExpandFolders TOGGLE=3 SELECT=dirs

Expand selected folders (or all if nothing selected) only the top level.
Use it in conjunction with Shift for expand at max depth.
Also, use it in conjunction with Ctrl for select items beneath expanded folders.
=return "ExpandFolders EXPAND" + (KeyDown("shift") ? "" : "=top") + (KeyDown("ctrl") ? " SELECT" : "");
Expand All_Selected.dcf (563 Bytes)

Know Issues

  • When expanding a branch for the first time, there may be a delay because DOpus needs to read new item's info.

Changelog

v1.6.0 (Apr 21, 2024): ExpandFolders.opusscriptinstall (5.8 KB)

  • Now the dialog use font name/size configured in Preferences / Colors and Fonts / Fonts > Dialogs.
  • SELECT can be used in Libraries.
  • Better logging system.
  • Minor improvements.
Full changelog

v1.5.1 (Mar 09, 2024):

  • Added in Script Config a new value : Expanding Dialog Delay, allows you to set the delay time before showing the expanding dialog (useful for shorter expansions). Default is 1 second (1000).
  • Minor changes.

v1.5.0 (Mar 01, 2024):

  • Improved overall logic when expanding/collapsing.
  • New int value for EXPAND and TOGGLE, to refer to an specific level when expanding.
  • levels and collevels values have been removed from COLLAPSE and TOGGLE respectively. Now the command respect the option in Preferences / File Displays / Folder Expansion : Collapse sub-folders within collapsed folders.
  • Added in Script Config a new value : Max Timeout when Expanding, to customize the maximum time in milliseconds that the command will wait after each level expansion to abort the entire command. By default is 15 seconds (15000).

v1.4.0 (Feb 28, 20024);

  • Internal build.

v1.3.0 (Feb 22, 2024):

  • COLLAPSE has a new value : levels, to effectively collapse all the expanded folders in all levels.
  • Added colparent and collevels values for TOGGLE, to enable the corresponding values for collapse.
  • A problem with the custom progress dialog that interfered with other listers/windows, minimizing/bringing them to the front, has been fixed.

v1.2.1 (Feb 11, 2024):

  • Now when expanding only the top level, is no longer initialized a new thread.
  • Added SELECT and SELECT=dirs, which allows to select the files/dirs beneath the new expanded folders by the command.

v1.1.0 (Feb 02, 2024):

  • Added new argument: TOGGLE and TOGGLE=expandtop, for toggle between two states
  • New custom progress dialog when expanding.

v1.0.1 (Jan 24, 2024):

  • Added new argument: EXPAND and the subvalue EXPAND=top to only expand the first level in folders.
  • Now when collapsing, you can select files to collapse their parent folder.
  • Added new subvalue COLLAPSE=parent, to collapse parents for selected folders as well.

v1.0.0 (Jan 23, 2024) Initial release

6 Likes

hello, it's a nice script.
may be it would be useful to add this feature? (collapse on selected files or subfolders)
and may be this would be a little faster if you limit folder's depth as Leo says to 10 or similar.
thank you so much

I think that is quite feasible to implement. I'll take a look at it when I have free time. Thank you.

If I understand correctly what Leo suggests, that would only work to expand all folders, and with certain drawbacks as well:

  • Would the command end up running Go EXPANDBRANCH 10 times for any scenario, even when there's only 1 folder to expand? Or how would I know when to stop without consulting (updating) the tab data ?

Update v1.0.1:

  • Added new argument: EXPAND and the subvalue EXPAND=top to only expand the first level in folders.
  • Now when collapsing, you can select files to collapse their parent folder.
  • Added new subvalue COLLAPSE=parent, to collapse parents for selected folders as well.
3 Likes

Interesting work, as usual! And needed to round out Expandable Folders options.

As a beta tester, I think I found the following:

If I run ExpandFolders on any set of folders of depth 0 or 2, the folders are expanded. If I immediately run ExpandFolders COLLAPSE ALL (the originally selected folders are still selected) nothing at all happens. If I then deselect all items and run ExpandFolders COLLAPSE ALL, all the folders collapse.

If the set of folders includes at least one folder with a depth of 2, and I run ExpandFolders and then immediately run ExpandFolders COLLAPSE ALL, all the folders collapse.

Can you duplicate this?

Fixed. Thanks! Please download the new version now.

Sorry, I don't think I'm understanding corrrectly this one. If you run ExpandFolders COLLAPSE ALL, all the folders are going to be collapsed, despite the previous command.

1 Like

can i set just one hotkey with this script to expand and collapse (if there is expanded but nothing selected) folders as in your beatiful code from here

Thanks so much for the quick fix. The second part is my long-wined way of saying that COLAPSE ALL worked of the folders of depth 2 or more. Thanks, again.

For what is worth, COLLAPSE ALL means collapse all visible folders in current file display, not only the one's who are nested behind a selected folder.

Since I had some more time today, I was playing a bit with this command to adapt it more to my needs. I have ended up extending it more than I expected :grin:
The v1.1.0b brings with:

  • TOGGLE to automatically switch between collapse or expand. Please note that if used with ALL, the command collapses folders if any expanded folder exists or expands otherwise. Without ALL, it checks only the selected folders (that is, it checks the set of folders as a whole).
  • Since there is a small freeze every time the tab data is updated, the breadcrumbs bar busy indicator implemented was unusable, so I replaced it with a dialog of its own. This means:
    • When expanding, the command run as a separate program (using dopusrt.exe), and intercommunicate with the dialog.
    • You have a better record that the command continues expanding (very useful for use with deep folder nests).
    • You can stop the expansion in a more user friendly way at any time.
    • Expansion runs slightly faster.

You can test it by downloading v1.1.0b from the main post. As usual, leave here your comments/suggestions/error findings. Beta testers always come in handy :smiley:

1 Like

Hello. DOpus hangs if i cancel script via new dialog.

Can you be more specific?
What was the full command line?
In what condition/scenario? In order to reproduce the issue.

i use ExpandFolders TOGGLE with no selected folders on my desktop folder. after 12-17sec i click "Cancel" and Dopus hangs - can't even select one file. But after 1.5-2min DO came back to life.

Out of curiosity, with how many files and folders do you end up when fully expand the desktop? You may try with Everything to quickly find out. Do you have links, softlinks, etc sitting in there?

41 folders of first level and 200k files at all)))
image

Probably DO dealing with calcs for every value in every column for all those files plus updating tab data was the cause for the freezing? :slight_smile: I don't recommend fully expansion in that conditions.

yes, of course, but canceling doesn't work anyway. maybe it's an Opus issue?
(and I didn't know how many files I had there, it came out by accident)

It does work, but the command queries the cancel status after each expanded level, so to speak. It doesn't cancel the current level calculation or the column calculations and so on. If you can check the total number of files in your desktop through Everything, there are probably more.
Perhaps doesn't hurt add some mechanisms to stop the process if the user falls into a long expansion by mistake...
@fkast does the freezing also happens if you turn on FLATVIEW in the desktop folder, in order to fully expand it?

nope. goes instantly

That's very odd to say the least :smile:.
I add some extra checks to avoid this kind of situations.
I do check trying to expand the whole Users folder and cancel after a while :smile:
Please note that when you cancel, there's still a small dead time, that's the tab updating their data.
Feel free to download v1.1.0 b2 in the main post to see how it goes now.
Thanks for your feedback btw.