I am trying to build certain modules in Mathematica 9. I want it to dynamically ask for the directory path ( like file explorer ) when the code cell is executed.

How can I do that ?

(*================================================= DIRECTORY CONTROL \============================================*)

(*current directory*)
SetDirectory[NotebookDirectory[]];(*set to local roaming directory *)

(* set to local roaming SubDirectory *)
  • $\begingroup$ @rm-rf -rf Thank you. How can I enable the pop up by default. Shift+Enter should display the folder Browser window. Is there a method to do that ? $\endgroup$ Apr 24, 2013 at 21:58

2 Answers 2


To choose the directory interactively, use SystemDialogInput, which brings up a native dialog


enter image description here

If successful, it'll return the chosen directory as a string, or return $Canceled if you select "Cancel".

  • $\begingroup$ Exactly what I want. $\endgroup$ Apr 24, 2013 at 22:04
  • $\begingroup$ Any way to add custom message like : choose the sub folder or choose the subsubfolder ... It may create confusion when more than one such dialog pop up right ... $\endgroup$ Apr 24, 2013 at 22:10
  • $\begingroup$ It would be bad UX to have multiple popups appearing at the same time for such a simple (and common) operation. Instead, if you're using something like a Button[] for your interface, consider a descriptive name for the button, such as Button["Choose directory", dir = SystemDialogInput["Directory"]] $\endgroup$
    – rm -rf
    Apr 24, 2013 at 22:13
  • $\begingroup$ Ok sounds good. Thanks a lot ! $\endgroup$ Apr 24, 2013 at 22:17

Extending R.M's answer:

Button["Choose directory", dir = SystemDialogInput["Directory"], Method -> "Queued"] 

works without error.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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