Help with if else statement

I’m sure there is something very simple i’m missing here… This evaluates as none for everything. Hopefully you can tell what i’m trying to do here. But there are 3 possible files that exist in a directory. I would like to output 1.0.2, 1.0.3, 1.04, or none depending on what the client finds. Please help me fix it. Thanks in advance!

(if exist file “S:\ftp_root\webapat\WSS_Version_1.0.2” AND not exists file “S:\ftp_root\webapat\WSS_Version_1.0.3” AND not exists file “S:\ftp_root\webapat\WSS_Version_1.0.4” then “1.0.2” else if exists file “S:\ftp_root\webapat\WSS_Version_1.0.3” AND not exists file “S:\ftp_root\webapat\WSS_Version_1.0.4” then “1.0.3” else if exists file “S:\ftp_root\webapat\WSS_Version_1.0.4” then “1.0.4” else if not exist file “S:\ftp_root\webapat\WSS_Version_1.0.2” AND not exists file “S:\ftp_root\webapat\WSS_Version_1.0.3” AND not exists file “S:\ftp_root\webapat\WSS_Version_1.0.4” then “none” else it)

At the end of the last check , “else it”, “it” has no context.
In fact you don’t need to check the last condition at all - the first three checks have all failed already so you know none of the files exist, so replace

else if not exist file “S:\ftp_root\webapat\WSS_Version_1.0.2” AND not exists file “S:\ftp_root\webapat\WSS_Version_1.0.3” AND not exists file “S:\ftp_root\webapat\WSS_Version_1.0.4” then “none” else it)

With

Else "none"

Logically, it looks like you’re returning the lowest of the three versions found, so possible replace it all with

minima of (it as version) of following texts of lasts "_" of names of files whose (name of it starts with "WSS_Version") of folders "S:\ftp_root\webapat"

Edit - I think you’re missing the condition where 1.0.2 and 1.0.4, but not 1.0.3, exist; but I’m not sure your intent there.

Edit 2 - changed “minimum” to the plural “minima” so the case of “all files missing” gives an empty result without a 'Singular Expressions error.

Thank you! I’m actually looking for the highest version so I used maxima instead of minima and it worked perfectly!

1 Like