Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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 \============================================*)

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

SetDirectory["File_Directory"];
(* set to local roaming SubDirectory *)
share|improve this question
    
@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 ? –  abhilash sukumari Apr 24 '13 at 21:58
add comment

1 Answer

up vote 4 down vote accepted

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

SystemDialogInput["Directory"]

enter image description here

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

share|improve this answer
    
Exactly what I want. –  abhilash sukumari Apr 24 '13 at 22:04
    
thanks @rm -rf ... –  abhilash sukumari Apr 24 '13 at 22:04
    
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 ... –  abhilash sukumari Apr 24 '13 at 22:10
    
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"]] –  rm -rf Apr 24 '13 at 22:13
    
Ok sounds good. Thanks a lot ! –  abhilash sukumari Apr 24 '13 at 22:17
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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