External Control Codes seemingly not updated within a function on selection change

Let's say I start with some item focused/selected in the middle of a folder:

SubfolderA
SubfolderB   <- I am 'sitting' on this one
SubfolderC

At this point, I invoke the following Standard Function (via a button):

Select NEXT
dopusrt /ArgsMsgBox {f}

The message box displays "SubfolderB" (well, with full path, but you get the idea) instead of "SubfolderC". Inserting a delay between the commands does not change anything - but I can see that selection got successfully moved to SubfolderC before the message box gets displayed.

What am I missing? Are External Control Codes evaluated/set on entry into the function and never updated? Thanks!

The Select command is for changing the selection in the file display. It isn't for changing which items subsequent commands work on. (It can be used for that in some situations, but it's usually the wrong way to do things.)

What's the bigger picture on what you're aiming to do?

Well, I was simply trying to understand why this "Next Sibling Folder" code does not work (even with the line breaks that are missing from that post). It's just a learning exercise since your Go-Relative command and Julianon's JS update both work very well (thanks x 2!).

Oh, I see. That's what I thought, but it wasn't obvious.

Could you expand please? What would be the situations where Select would affect subsequent commands? Alternatively, what would be the right way to achieve the expected results from, say, the simplified code snippet in the OP. Like I said, this is not to solve a specific problem, but to gain a better understanding of how things work (in Standard Functions - for now).

Thank you!

The command in that thread doesn't work because it's, well, incorrect. :slight_smile: The person who posted it was just guessing, and wondering why it didn't work. (I've fixed the linebreaks in the other thread, too.)

A working method can be found here:


I'd recommend not using the Select command for this at all. It's the wrong tool for the job. If you want a command to act on a file/folder/path, other than the things that are selected when you click the button, then you should usually feed the path to the command and not try to change the selection using the Select command.

That can be done using an explicit path or wildcard, with many commands, or via scripting if needed. With scripting, you have full control over the list of paths each command acts on.

(Scripts can also run the Select command and then request an updated snapshot of the selection afterwards, although I still would not recommend doing that as it's still going to mess around with the user's selection for what is really internal script variables/logic. A general rule is: Don't use the user's selection, or clipboard, or anything like that, to store what are effectively script/command variables, as it is annoying to run a command and have it trash state it didn't need to modify.)

There may be some cases where using Select makes sense or is easier, but they are not the norm and you shouldn't go to it as your first choice in trying to solve this kind of thing. That's not what it's for.

The Select command is for changing what the user sees is selected, and what subsequent buttons which the user clicks will act on. It is not for a button or script to modify the inputs to subsequent commands in the same button or script.

Understood. Thank you for your detailed and clear explanation!