Ban folders to execute commands (specific case)

Hello,

Ban folders to execute commands

I made a button that rename 2 or more files, if their extensions are different, with the same name. It's useful to rename a movie and its subtitle :wink:

@filesonly @nodeselect Rename TYPE=files REGEXP PATTERN="^(.*)(\.[^.]+)$" TO="{dlgstrings|Enter new name}\2"

It works great on files but although it doesn't rename selected folders it opens dialog box for them anyway as if it were ready to do the job. Please test it to see what I mean.

Notice that @filesonly and Rename TYPE=files are there and prevent nothing about folders.

Is there a way to prevent this behavior on folder, none dialbox opens ? Or is there a way to customize an error dialbox that warns that folders are not allowed ? And is it a bug or am I the bug ?
:wink:

All of this is my understanding. And while I may not have things 100% technically correct, it is still helpful to think of your more complex custom Opus commands in these terms.

As I understand them, these are the phases of Opus command execution. Except as noted, this all applies to Internal Functions, External Functions, and MS-DOS Batch Functions.[ol][li] The user initiates a command function by clicking on a button or menu item, or by pressing a hotkey.
[/li]
[li] Opus parses the entire command function, in preparation for execution. During this phase Opus will do the following (I do not know in what order):[ol][li] Display all dialog prompts to the user.[/li]
[li] Replace all file/folder attributes (e.g. {sourcepath$}, {file$}, et cetera) with the actual expanded values.[/li]
[li] Execute all @set Opus variable declarations, and expand all {$VariableName} references to the declared values.[/li]
[li] For user commands, replace all option and parameter references from the user command's template with the actual expanded values passed to the user command.[/li]
[li] Setup the command for execution based upon other modifiers and directives.[/li][/ol]
NOTE: As you can see, there is a lot of work going on during this phase, but the command function itself has not been executed yet, it is just being setup for execution.
[/li]
[li] For MS-DOS Batch functions only, Opus writes a temporary script, named like "dop.bat" to your %Temp% folder. (I don't know where Opus caches an Internal or External command function.)
[/li]
[li] Opus executes the cached command (internal/external/MS-DOS batch) function.[/li][/ol]

So with the above in mind, using the @filesonly directive means the command will only execute for selected files. But the command will still be parsed, and that means the {dlgstingS} dialog will still appear. Currently, Opus does not provide a means to conditionally prompt the user by itself. In fact, if you select nothing at all, the command function below will still run Notepad. This is correct behavior, in accordance with the current Opus design.

@filesonly Notepad

The Rename TYPE option only affects the Rename command, it has nothing to do with the whole command function. So again, this is correct behavior, in accordance with the current Opus design.

[quote="kenalcock"]So again, this is correct behavior, in accordance with the current Opus design.
[/quote]
Ok but does it mean this behavior is frozen in Opus development ?

I give my vote for changing it. Who's next ? :wink:

Well, I guess I should talk about that in my mail to GPSoftware.

You could deselect all folders at the start of the button if the problem is accidentally renaming folders you didn't realise were selected.

Using either (or both) @filesonly and Rename Type=files will prevent any selected folders from being renamed. But neither will (or should) prevent the user from being prompted by {dlgstringS} when only folders are selected.

Just know that the folders are not actually being renamed, don't click the button when you only have folders selected, or click cancel when {dlgstringS} prompts you.

Leo I suppose you're talking about the SELECT function. Good idea that I had myself but unfortunately with this command pattern:

select [option] rename [dlgstring]
select is always run after rename anyway. See one of my previous post.

[quote="kenalcock"]Just know that the folders are not actually being renamed, don't click the button when you only have folders selected, or click cancel when {dlgstringS} prompts you.
[/quote]
Yes, I already do it but I care of all other DOpus users (laptop is shared with girlfriend) that might be confused. And I'm glad to contribute to DOpus enhancement. :smiley: