[?] Run a function using an If expression with "!=" ?

I have a function called
processFile[fname_]…

The function works correctly when called as

processFile[fileName]

However, I want to call it thus:

fname = SystemDialogInput["FileOpen"];
If[fname != $Canceled, processFile[fname], "Error"]

When I select cancel, the If function returns Error, but when I select a file the If function returns

If["/Users/andy/Downloads/pqs.csv" != $Canceled, processFile[fname], "Error"]

What am I doing wrong?

Cheers
Andy

Andy,

Use =!= (not same) instead of != because MMA knows they are not the same but does not know if they are “equal “. Read the documentation to get a more thorough description of the difference between same and equal.

Regards

Neil

Oh, that’s interesting. Thanks very much.
I will dig into how MMA handles equality in more depth.

Cheers
Andy