"Copy to Clipboard" tree representation when expanded folders enabled

When we select some Name column cells, i.e. files or folders (not date or type column cells etc), from the file display with folder expansion is enabled, it would be great if we could copy the selected cells as a tree representation. Meaning, something similar to using the Windows tree command.

Normally I can run tree on a path (e.g. via a button script), then edit it after the fact in a text editor to remove any unwanted files or unnecessarily deep paths from the tree representation, but this is tedious and error prone. This proposed feature would be like a live edit of the final tree representation before you copy it.

So for this example cell selection from the Name column:

dopus_2024-07-01_23-28-50

Using the tree /F command's output style as a guide, we'd copy:

Note the lack of broadcast.js since that Name cell isn't selected (despite the steamui folder being selected and expanded), as well as the lack of the unselected file cells directly under Steam.

C:\Program Files (x86)\Steam
│   GameOverlayUI.exe.log.last
│   Steam.dll
│   steam.exe
│
├───steam
├───steamapps
├───steamchina
├───steamui
└───steamui-public

The difference between this FR and tree is that tree can only accept a single path and it always goes to the max depth. This FR however would limit the tree representation to the selected cells -- or just the visible cells under the selected expanded folder cell.

I imagine 2 hypothetical options to be added to selected cells' right-click menu:

  • Copy to Clipboard (tree as selected) (like the example above).
  • Copy to Clipboard (tree as expanded) (like the example below).

dopus_2024-07-01_23-35-00

In this second example, only 2 cells are selected, but we could use the just mentioned Copy to Clipboard (as expanded) option instead which would copy the following tree representation to the clipboard:

Note the inclusion of broadcast.js this time and all the files beneath Steam, also, the RivaTuner Statistics Server folder is included, but because it's not expanded, only the folder is added to the tree representation, not any of its contents.

C:\Program Files (x86)\RivaTuner Statistics Server
C:\Program Files (x86)\Steam
│   GameOverlayUI.exe.log.last
│   Steam.dll
│   steam.exe
│   steam.signatures
│   Steam2.dll
│   <other file cells beyond the screenshot>
│
├───steam
├───steamapps
├───steamchina
├───steamui
    │   broadcast.js
├───steamui-public
└───steamui-public

Presumably this feature would be limited to only when folder expansion is enabled as I'm not sure how well it would work in flat view for example. I'm also not sure how well I explained the idea, or if it's worth the effort to implement, but the idea came over me and I thought I'd see it through. Would anyone else find this useful?

Thanks.

Opus 13.7.1

1 Like

FWIW, this can be done via a script (IMHO it's a good exercise to develop basic scripting skills).
If you don't mind, can you share a real life scenario where this could be useful?

I agree, but so could the choices that Opus ships with. I just thought it might be useful to offer another way of copying cells:

dopus_2024-07-02_15-51-24

I'd probably have a hard time getting the FR working as I have described, but sure, perhaps it should be left to the community to create.

The reason I even began thinking about this is because I wanted to show somebody (a bug report) what files and folders were present on my system, without exposing anything irrelevant or personal.

Usually I'd either take a screenshot and censor some items after the fact if necessary. The reasons why I thought a text tree representation would be better than a screenshot is that it's both searchable, and easier and faster to edit without any special tool. But why censor or edit when you could select exactly what you wish to share before copying? Hence this FR.

Understandable. Thanks.
But are you referring to whether it works with the selected items or with the selected cells, as in your screenshot?
Note that there are some slight differences, when wanting to make a script command for one or the other. For example, if you are talking about cells, it is possible to select values other than the name. What should the script do in that case? Always use only names? Also include the values of selected cells? For everyone or only for the selected ones?

The only reason I went the cells route for this suggestion is that that is how we copy File Display information currently (Ctrl + Right-clicking to select cells, then right-clicking to copy them via context menu). The feature could alternatively be done using normal selection of File Display items (Ctrl / Shift + left-clicking), but where would the copy feature be triggered from? It seemed to be worth grouping with the cell copying features as seen in the previous screenshot.

I used the terminology "Name cells" because it would only work with those. If other cells for different columns were selected, they could either just copy the Name cell for that row anyway, or ignore the cell because the other cells don't really have a place in a tree representation (unless we want to start adding e.g. file size and other info to each of the tree's items:

C:\Program Files (x86)\Steam [1.56 GiB; Modified: 2024-07-02]
...
│   steam.exe [4.20 MiB; Modified: 2024-07-02]
│   steam.signatures [4.45 KiB; Modified: 2024-07-02]
...

...but that's beyond what I was originally thinking.

As I outlined, there could be two options: Copy to Clipboard (tree as selected) and ...as expanded. The latter would be more like for every Name cell under selected folder cells (but only if that folder is also expanded -- that's the live edit aspect).

It's possible the idea could be improved upon as you might want an even simpler third copy operation, i.e. one which disregards if the select folder cell is expanded or not, but then the copied result becomes just two or more tree commands joined together, which still has its uses as you could still use it to omit paths you don't want in the tree:

A
├───B1
├───B2
└───B3

To make a tree of the folders B1 and B3, instead of normally having to pass A's path to tree then edit the output after to erase B2 and the indentation from A, you could highlight B1 and B3 and effectively get two trees joined together at the root level of indentation. I only use tree as an example. There are probably tools which are far better than it, i.e. which support multiple paths, exclusions etc when defining a text tree to draw. That might be what I need to look into, but passing selected cells to a third-party program wouldn't consider if the folder cell is expanded or not I guess.

The reason for the copy operation considering whether a folder is expanded or not was only suggested as it would give you control over whether the contents of a folder is also included or only its presence (i.e. none of its child items, just the folder). These ideas could do with further simplifying I think.

Hopefully I'm making sense.

What would be the output if, as in your first example, you select the 'Steam' folder and the broadcast.js' file only?

If you're going to write a script for it, this other script I made might have some logic in there that might be helpful: Script for copying selected relative file paths list from Flat View

It's for a different purpose and only works with selected files, but some of it will be relevant like how it gets the relative paths. You could also subtract the sourcePathDepth and initialDepth variables to calculate the length of the tree branches for each file for example.

Edit: Actually I gave ChatGPT my original script and told it to generate a new one that draws a tree instead, and it actually worked :skull: I'll probably touch it up a bit with additional features when I get the chance and make a thread for it, but I'll paste it below. At the moment it only works with selected files/folders but I'll see about adding stuff to give it the expanding options you mentioned. Also right now it seems to draw the tree a bit funky with an extra layer of lines at the bottom level of selected files.

Edit 2: I polished up the script, here's a thread with it: Script / Command for copying tree view of selected files & folders