0
$\begingroup$

Consider the following code

Button["Import", file = SystemDialogInput["FileOpen"]; 
 data = Import[file], Method -> "Queued"]

which yields a button which, upon clicking, opens a directory window from which I can access my files and import one. However, in Windows 10, if I click "Cancel", that is,

enter image description here

I get back the following message, regarding $Canceled,

enter image description here

How do I avoid such a message? That is, if I click "Cancel" I want both file and data to remain non attributed.

I thought about simply checking whether data or file are Unevaluated[Sequence[]], but not sure how to do this or if there is a better way of doing it.

Any ideas?

$\endgroup$

1 Answer 1

3
$\begingroup$

I'm new and this is my 1st answer. Try the following:

Button["Import", file = SystemDialogInput["FileOpen"]; 
If[ Not@TrueQ[file == $Canceled], data = Import[file]], 
Method -> "Queued"]
$\endgroup$
1
  • $\begingroup$ That works, thank you!! $\endgroup$
    – sam wolfe
    Mar 16, 2020 at 22:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.