# How to choose a file by open\_dialog prompt?

**URL:** <https://discourse.julialang.org/t/how-to-choose-a-file-by-open-dialog-prompt/71157>\
**Category:** General Usage\
**Tags:** question, windows, io\
**Created:** [November 8, 2021, 3:58pm UTC](https://discourse.julialang.org/t/how-to-choose-a-file-by-open-dialog-prompt/71157 "2021-11-08T15:58:51Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amro](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Amro](https://discourse.julialang.org/u/Amro)\
**Post date:** [November 8, 2021, 3:58pm UTC](https://discourse.julialang.org/t/how-to-choose-a-file-by-open-dialog-prompt/71157/1 "2021-11-08T15:58:51Z")

</div>

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?

```julia
using Gtk
#file = "C:/Users/.../My_file.txt";
file = open_dialog("My first file dialog")
filehandle = open("$file"); 
Netlist_lines = readlines(filehandle);
close(filehandle); 
Netlist_lines[1][begin:3]

```

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [November 8, 2021, 4:12pm UTC](https://discourse.julialang.org/t/how-to-choose-a-file-by-open-dialog-prompt/71157/2 "2021-11-08T16:12:52Z")

</div>

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.

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

---

<div class="post-metadata">

**Author:** ![Amro](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Amro](https://discourse.julialang.org/u/Amro)\
**Post date:** [November 8, 2021, 4:16pm UTC](https://discourse.julialang.org/t/how-to-choose-a-file-by-open-dialog-prompt/71157/3 "2021-11-08T16:16:01Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [November 8, 2021, 4:18pm UTC](https://discourse.julialang.org/t/how-to-choose-a-file-by-open-dialog-prompt/71157/4 "2021-11-08T16:18:58Z")

</div>

No idea if this is a new Win11 feature or something else.  
You could try using one the alternative methods [presented in this thread](https://discourse.julialang.org/t/file-choose-in-julia/69703).

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [November 8, 2021, 5:00pm UTC](https://discourse.julialang.org/t/how-to-choose-a-file-by-open-dialog-prompt/71157/6 "2021-11-08T17:00:11Z")

</div>

Yes, I would recommend using the [NatifeFileDialog.jl package](https://github.com/Suavesito-Olimpiada/NativeFileDialog.jl) if all you need is a file dialog.

---

<div class="post-metadata">

**Author:** ![Amro](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Amro](https://discourse.julialang.org/u/Amro)\
**Post date:** [November 8, 2021, 5:05pm UTC](https://discourse.julialang.org/t/how-to-choose-a-file-by-open-dialog-prompt/71157/7 "2021-11-08T17:05:55Z")

</div>

@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”

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

```

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [November 8, 2021, 5:42pm UTC](https://discourse.julialang.org/t/how-to-choose-a-file-by-open-dialog-prompt/71157/8 "2021-11-08T17:42:33Z")

</div>

> [@Amro](#):
>
> `pick_file(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")`

---

<div class="post-metadata">

**Author:** ![Amro](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Amro](https://discourse.julialang.org/u/Amro)\
**Post date:** [November 8, 2021, 5:45pm UTC](https://discourse.julialang.org/t/how-to-choose-a-file-by-open-dialog-prompt/71157/9 "2021-11-08T17:45:28Z")

</div>

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

```julia
ERROR: LoadError: Error creating ShellItem
Stacktrace:
 [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 - polymtl.ca\AmroAlsabbagh\Code\Julia\Tests and Notes\11- Popup prompt\openprompt.jl:5
in expression starting at c:\Users\amroa\OneDrive - polymtl.ca\AmroAlsabbagh\Code\Julia\Tests and Notes\11- Popup prompt\openprompt.jl:5

```

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [November 8, 2021, 8:19pm UTC](https://discourse.julialang.org/t/how-to-choose-a-file-by-open-dialog-prompt/71157/10 "2021-11-08T20:19:26Z")

</div>

Looks like an error coming from the underlying C library [nativefiledialog](https://github.com/mlabbe/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 [https://github.com/Suavesito-Olimpiada/NativeFileDialog.jl](https://github.com/Suavesito-Olimpiada/NativeFileDialog.jl)

---

<div class="post-metadata">

**Author:** ![Amro](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Amro](https://discourse.julialang.org/u/Amro)\
**Post date:** [November 8, 2021, 8:27pm UTC](https://discourse.julialang.org/t/how-to-choose-a-file-by-open-dialog-prompt/71157/11 "2021-11-08T20:27:23Z")

</div>

Thanks, I got it
