How to choose a file by open_dialog prompt?

I am trying to select a file by using open_dialog() instead of defining the path of the file. However, after the prompt window is opened and I navigate to the file, I cannot really select it and the prompt window is not closed. Any further issues I need to do on the below MWE code?

using Gtk
#file = "C:/Users/.../My_file.txt";
file = open_dialog("My first file dialog")
filehandle = open("$file"); 
Netlist_lines = readlines(filehandle);

It works well with Julia 1.7 Win10, Gtk v1.1.9: once a file is selected in the dialog window and the Open button hit, the window closes.

not an issue but open("$file") does the same as open(file)

1 Like

I see. thank you very much.
I am using VS code with julia v1.4.2 at win 11, and after I select the file and hit the open button, nothing is done.
any recommendation to solve it?

No idea if this is a new Win11 feature or something else.
You could try using one the alternative methods presented in this thread.

1 Like

Yes, I would recommend using the NatifeFileDialog.jl package if all you need is a file dialog.


@stevengj Thank you. I have tried NativeFileDialog and it works in my case.
I have further issue that if I need to add a basic directory to the pick_file() such as I want the prompt window to open at first at this directory ““C:/Users/…”. Do you know what should I do?
I used the below, but it gave me an error”

pick_file(path="C:/Users/"; filterlist="txt;net");
ERROR: LoadError: MethodError: no method matching pick_file(::String; path="C:/Users/", filterlist="txt;net")

path isn’t a keyword argument, so you don’t give it a name when calling the function. Try
pick_file("C:/Users/"; filterlist="txt;net")

@stevengj I used pick_file("C:/Users/"; filterlist="txt;net")
and it gave me the below error

ERROR: LoadError: Error creating ShellItem
 [1] error(s::String)
   @ Base .\error.jl:33
 [2] pick_file(path::String; filterlist::String)
   @ NativeFileDialog C:\Users\amroa\.julia\packages\NativeFileDialog\zr2CK\src\NativeFileDialog.jl:58
 [3] top-level scope
   @ c:\Users\amroa\OneDrive -\AmroAlsabbagh\Code\Julia\Tests and Notes\11- Popup prompt\openprompt.jl:5
in expression starting at c:\Users\amroa\OneDrive -\AmroAlsabbagh\Code\Julia\Tests and Notes\11- Popup prompt\openprompt.jl:5

Looks like an error coming from the underlying C library nativefiledialog … maybe it doesn’t like how you are specifying the path? e.g. try raw"C:\Users"

… you could also try filing an issue at GitHub - Suavesito-Olimpiada/NativeFileDialog.jl: mlabbe/nativefiledialog julia wrapper


Thanks, I got it