Message Boards Message Boards

defining the default directory in FileNameSetter

I am trying to set the default directory in FileNameSetter.

If I simply do:FileNameSetter[$UserDocumentsDirectory] hitting the Browse button will start in the the defined directory, but in the following code:

SetDirectory[ToFileName[{$HomeDirectory, "Desktop"}]];
DialogInput[{filename = ""}, 
 Column[{"Either type your file name (in quotation marks and with the \
file extension) or browse for yo", 
   InputField[Dynamic[filename], String, 
    FieldHint -> "Enter your file name"], 
   FileNameSetter[Dynamic[filename], 
    "Open", {"text files" -> {"*.txt"}}, Method -> "Preemptive"], 
   DefaultButton[DialogReturn[filename]]}]]

I can't figure out how to add a default directory option (in this case I would like: ToFileName[{$HomeDirectory, "Desktop"}]). Anywhere I add it seems to mess up the definition of FN[ct] and/or filename.

I would appreciate any advice you may be able to provide.

Thanks,

Matty

POSTED BY: Matty Mookerjee
2 Replies

Is it this you are looking for?

DialogInput[{filename = FileNameJoin[{$HomeDirectory, "Desktop"}]}, 
 Column[{"Either type your file name (in quotation marks and with the \
file extension) or browse for your file:", 
   InputField[Dynamic[filename], String, 
    FieldHint -> "Enter your file name"], 
   FileNameSetter[Dynamic[filename], 
    "Open", {"text files" -> {"*.txt"}}, Method -> "Preemptive"], 
   DefaultButton[DialogReturn[filename]]}]]

Henrik

POSTED BY: Henrik Schachner

Henrik

Yes, that works. Actually, it works better because the user, if they decide to type the file name, no longer has to put it in quotation marks (which they often forget to do).

I was really stuck on it having to be an option in FileNameSetter; I didn't think about how I could change something in the DialogInput.

Thank you so much.

Matty

POSTED BY: Matty Mookerjee
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract