Is there any equivalent for IF...THEN...ELSE in DOpus?

Dear friends,

As far as I know, DOpus have not any conventional commands. How to I emulate conditions such as follow:

if {f}="" then {RS|test1} else {RS|test2} end

I used the following code under MS-DOS Batch Function, but not worked correctly:

[code]Call Set Files = {f}

If %Files%=="" (
{RS|Test1}
) Else (
{RS|Test2}
)[/code]

Best Regards

I have an answer, but almost certainly it isn't the answer you are looking for.
I'll be disappointed if I don't see a better answer to this posted tomorrow morning.

My answer is this:[ul]1) write a batch file external to the the button.
In other words write a file named If-Then.bat.

If %1 == " " SET /P test1= Enter Test1 If Not %1 == " " SET /P test2= Enter Test2
2) Make a button using MS-DOS Batch function.

Call If-Then.bat {f} pause[/ul]
This doesn't use {RS}, it prompts for a string at the command line.
The string entered is then %test1% or %test2%.
Not quite what you wanted, but it does solve the problem you posted.

Regards,
David

There isn't any conditional logic in Opus's command "language" (if you could call it that) at the moment. You have to pass the filenames and other details you want to work with to some kind of external script or program. (Batch file, VBScript, Perl, etc.)

From those scripts, if you want to execute Opus commands, you have to run them via

dopusrt.exe /cmd <command here>

There is a way to include the VBScript itself in the button, so you don't have to have the script in a separate file somewhere and can keep everything in one place in your Opus configuration. See this post:

"Abusing" Rename Scripts to do other things with file info

Dear Zippo & Leo, thank you very much for your replies. Your ideas help me to solve my problem :laughing:

@Zippo
Your code gave me an idea to use a Function instead of external BAT file. I don't know why I was not thinking about a function before your favor :exclamation:.

@Leo
Your suggestion about using dopusrt.exe in a VBScript code was the base of my solution as always :wink:

Rename scripts were not useful for my aim, because they are triggered just when a file is selected, but I want to execute a task if a file/dirs is selected and execute another task if any file/dir is not selected. After combining Zippo and Leo suggestions, I lead to the following solution:

  1. I create a new Script function called "test" with following code. The function have a template command named strFileName:

[code] @script vbscript
Option Explicit

Dim strDOpusrt
strDOpusrt = "C:\Program Files\GPSoftware\Directory Opus\DOpusRT.exe"

Dim Shell
Set Shell = CreateObject("WScript.Shell")

Dim strSelectedName
Dim command

strSelectedName = "&strFileName&"

if strSelectedName = "" then
command = """" & strDOpusrt & """" & " " & "/cmd" & " " & "{RS|Test1}"
Shell.Run(command)
else
command = """" & strDOpusrt & """" & " " & "/cmd" & " " & "{RS|Test2}"
Shell.Run(command)
end if
[/code]

  1. I create a new button with following code:

@nofilenamequoting test "{f!}"

I hope this code be useful for other IF…ELSE…THEN needers.

Best Regards

PS: What was happened if IF…ELSE…THEN was an internal command on DOpus?

Does Someone know why IF...Else in my first code not worked under MS-DOS Batch function :question:

Best Regards

[quote="searcher123"] @nofilenamequoting test "{f!}" [/quote]

You could simplify that to this, if you want:

test {f!}

If it's a standard function then nothing much as those aren't recognised Opus commands and aren't (usually) recognised programs in the path, either. (i.e. there is no IF.exe, ELSE.exe, THEN.exe.)

If it's an MS-DOS function then it could cause all sorts of weird behaviour, unless you are careful not to use any Opus commands. If you mix Opus and non-Opus commands in an MS-DOS function then the function is split into several batch files which can cause the IF/THEN/ELSE logic to go haywire. Best to use an actual batch (or script) file in those cases.

[quote="leo"]You could simplify that to this, if you want:

test {f!}

No, I couldn't. With your code the function will not work right.

How come? What goes wrong?

whether a file/dir is selected or not, the function think that a file/dir is selected.

@nofilenamequoting has no effect on that.

I know that, but I used by my fear :slight_smile: I don't know if under a unknown condition a ""name"" be sent to the function what maybe happen. :unamused:

All I was saying is that these two commands are equivalent:

@nofilenamequoting test "{f!}"

test {f!}

Opus will automatically add the quotes around the path which {f!} emits, if the path contains a space and needs quoting.

I suppose there is a difference. If nothing is selected then the first example will run

test ""

while the second will run

test 

Whether those two produce different results is up to test. It's more common for things to check the number or arguments passed than to check for empty arguments, so I didn't consider that difference before.

By the way, if you don't want the button to do anything if nothing is selected, use {f} instead of {f!}. The former needs a selection and will prevent the button from running if there isn't one; the latter wants a selection and will pass nothing if there isn't one.