# \`file.choose()\` in \`Julia\`?

**URL:** <https://discourse.julialang.org/t/file-choose-in-julia/69703>\
**Category:** New to Julia\
**Tags:** filesystem, io, gui\
**Created:** [October 13, 2021, 5:15pm UTC](https://discourse.julialang.org/t/file-choose-in-julia/69703 "2021-10-13T17:15:07Z")\
**Posts on this page:** 20\
**Page:** 3

<div class="post-metadata">

**Author:** ![suavesito](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/suavesito/32/34386_2.png) [@suavesito](https://discourse.julialang.org/u/suavesito)\
**Post date:** [October 16, 2021, 8:56am UTC](https://discourse.julialang.org/t/file-choose-in-julia/69703/42 "2021-10-16T08:56:18Z")

</div>

Not need to left that in the startup file. [NativeFileDialog.jl](https://github.com/Suavesito-Olimpiada/NativeFileDialog.jl) first version is working, still test to add and documentation. Also I need to register it (reading right now how it is done).

---

<div class="post-metadata">

**Author:** ![Alex\_Tantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alex_tantos/32/10636_2.png) [@Alex\_Tantos](https://discourse.julialang.org/u/Alex_Tantos)\
**Post date:** [October 16, 2021, 9:02am UTC](https://discourse.julialang.org/t/file-choose-in-julia/69703/43 "2021-10-16T09:02:07Z")

</div>

Cool! When the package is registered i will assign the solution to your post, since, although the `Gtk` solution suggested above works fine, I think it is preferable to promote the JLL solution that is as close to the native `open file` dialogs as it gets.

---

<div class="post-metadata">

**Author:** ![suavesito](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/suavesito/32/34386_2.png) [@suavesito](https://discourse.julialang.org/u/suavesito)\
**Post date:** [October 16, 2021, 9:05am UTC](https://discourse.julialang.org/t/file-choose-in-julia/69703/44 "2021-10-16T09:05:39Z")

</div>

If you can test it on you machine and give feedback I would be really grateful. 🙂

---

<div class="post-metadata">

**Author:** ![Alex\_Tantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alex_tantos/32/10636_2.png) [@Alex\_Tantos](https://discourse.julialang.org/u/Alex_Tantos)\
**Post date:** [October 16, 2021, 9:14am UTC](https://discourse.julialang.org/t/file-choose-in-julia/69703/45 "2021-10-16T09:14:11Z")

</div>

So, I tested all the functions in `NativeFileDialog.jl` and they all work! I was not able to test the ones in the wrapper.jl, since I would need some documentation as to what kinds of arguments you expect to have. Looking forward to testing the wrapper!

---

<div class="post-metadata">

**Author:** ![suavesito](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/suavesito/32/34386_2.png) [@suavesito](https://discourse.julialang.org/u/suavesito)\
**Post date:** [October 16, 2021, 9:34am UTC](https://discourse.julialang.org/t/file-choose-in-julia/69703/46 "2021-10-16T09:34:55Z")

</div>

Don’t worry about what is inside `wrapper.jl`, those functions are just a thin layer above NFD for me to not worry about C interop too much. The only functions that matter are the ones exported (`pick_file`, `pick_multi_file`, `save_file`, `pick_folder`).

Just as a curiosity, what OS are you using? and what `@time using NativeFileDialog` says? I want to see if I can improve the time for loading, because I think it should be faster (I think the problem is that `GTK3_jll` is a dependency for Linux/FreeBSD for `NativeFileDialog_jll`, but it is not needed on Windows or MacOS, or even Linux if Gtk is installed).

Anyways, thanks for the help! 😃

---

<div class="post-metadata">

**Author:** ![Alex\_Tantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alex_tantos/32/10636_2.png) [@Alex\_Tantos](https://discourse.julialang.org/u/Alex_Tantos)\
**Post date:** [October 16, 2021, 9:49am UTC](https://discourse.julialang.org/t/file-choose-in-julia/69703/47 "2021-10-16T09:49:54Z")

</div>

Great! These functions are more than enough.

First time loading is very good:

```julia
julia> @time using NativeFileDialog
  0.006044 seconds (4.71 k allocations: 310.094 KiB, 26.74% compilation time)

```

And here is the machine info:

 ![Screenshot 2021-10-13 at 8.29.26 PM](https://global.discourse-cdn.com/julialang/original/3X/6/9/69a25c224dade3264032a86489cdca143312a5ad.png)

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [October 16, 2021, 9:52am UTC](https://discourse.julialang.org/t/file-choose-in-julia/69703/48 "2021-10-16T09:52:20Z")

</div>

That time looks a bit _too_ fast, I’d expect something of the order of 0.1 seconds. Do you have the package already loaded in that session, including from your startup file?

---

<div class="post-metadata">

**Author:** ![Alex\_Tantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alex_tantos/32/10636_2.png) [@Alex\_Tantos](https://discourse.julialang.org/u/Alex_Tantos)\
**Post date:** [October 16, 2021, 9:55am UTC](https://discourse.julialang.org/t/file-choose-in-julia/69703/49 "2021-10-16T09:55:29Z")

</div>

Oh! You are right! Although I started a new session, the package had been loaded through the `startup.jl` file. So, I deleted the relevant line from `startup.jl` and when I started a new session I got the following:

```julia
julia> @time using NativeFileDialog
  0.539846 seconds (920.25 k allocations: 44.807 MiB, 9.31% gc time, 48.80% compilation time)

```

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [October 16, 2021, 9:59am UTC](https://discourse.julialang.org/t/file-choose-in-julia/69703/50 "2021-10-16T09:59:21Z")

</div>

Do you also load Revise.jl in your startup file? Note that you can launch julia bypassing the startup file with

```julia
julia --startup-file=no

```

---

<div class="post-metadata">

**Author:** ![Alex\_Tantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alex_tantos/32/10636_2.png) [@Alex\_Tantos](https://discourse.julialang.org/u/Alex_Tantos)\
**Post date:** [October 16, 2021, 10:02am UTC](https://discourse.julialang.org/t/file-choose-in-julia/69703/51 "2021-10-16T10:02:08Z")

</div>

No. `Revise.jl` is not being loaded. In general, `startup.jl` has only a few “convenience” functions that are not relevant.  
Thanks for the tip! Didn’t know about it.

---

<div class="post-metadata">

**Author:** ![suavesito](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/suavesito/32/34386_2.png) [@suavesito](https://discourse.julialang.org/u/suavesito)\
**Post date:** [October 16, 2021, 10:10am UTC](https://discourse.julialang.org/t/file-choose-in-julia/69703/52 "2021-10-16T10:10:11Z")

</div>

Nice, I hadn’t thought about Revise slowing down the package loading… but not having it makes the time on my machine to go from `~0.9`s to `~0.2s`. I guess that time is okay and i don’t need to worry too much about it for now. :b

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [October 16, 2021, 10:36am UTC](https://discourse.julialang.org/t/file-choose-in-julia/69703/53 "2021-10-16T10:36:09Z")

</div>

On Mac it installed gtk jlls, which I thought were only needed for Linux right? Or do jlls not discriminate between platforms for their dependencies?

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [October 16, 2021, 10:45am UTC](https://discourse.julialang.org/t/file-choose-in-julia/69703/54 "2021-10-16T10:45:15Z")

</div>

> [@jules](#):
>
> Or do jlls not discriminate between platforms for their dependencies?

Pkg doesn’t have optional (e.g. platform-dependent) dependencies, so no, that’s not possible to do.

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [October 16, 2021, 12:03pm UTC](https://discourse.julialang.org/t/file-choose-in-julia/69703/55 "2021-10-16T12:03:40Z")

</div>

Interesting, for me on Linux with Julia v1.6.3 it takes

```julia
% julia -q --project=/tmp --startup-file=no
julia> @time using NativeFileDialog
  0.139741 seconds (404.16 k allocations: 24.629 MiB, 35.78% compilation time)

```

---

<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:** [October 16, 2021, 12:14pm UTC](https://discourse.julialang.org/t/file-choose-in-julia/69703/56 "2021-10-16T12:14:57Z")

</div>

Some reporting from Win10 Julia 1.7.0-beta4 with empty `startup.jl`:

```julia
@time using NativeFileDialog # 1.2 s (1.3 M allocations: 58 MiB, 0.87% gc time, 35% compilation time)
@time using Gtk # 1.7 s (1.3 M allocations: 81 MiB, 1.16% gc time)

```

Tested all NativeFileDialog.jl functions further below and some observations:

- The parameter `filterlist` despite of its name does not seem to accept multiple filters (like Gtk does)?
- `defaultpath` should probably be defined consistently in all functions as an optional keyword argument?

Code tested successfully:

```julia
using NativeFileDialog
path = raw"C:\Users\jrafa"
pick_file(defaultpath = path, filterlist = "txt")
pick_multi_file(defaultpath = path, filterlist = "txt")
pick_folder(path)
save_file(path, "txt")

```

---

<div class="post-metadata">

**Author:** ![Alex\_Tantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alex_tantos/32/10636_2.png) [@Alex\_Tantos](https://discourse.julialang.org/u/Alex_Tantos)\
**Post date:** [October 16, 2021, 12:33pm UTC](https://discourse.julialang.org/t/file-choose-in-julia/69703/57 "2021-10-16T12:33:20Z")

</div>

Just for the sake of completeness and following what @rafael.guerra did, on mac, for `using Gtk` you get slightly slower loading time…although I do not consider these as notable differences, to be honest.

> [@Alex\_Tantos](#):
>
> ```julia
> julia> @time using NativeFileDialog
> 0.539846 seconds (920.25 k allocations: 44.807 MiB, 9.31% gc time, 48.80% compilation time)
> 
> ```

```julia
julia> @time using Gtk
  1.316213 seconds (2.32 M allocations: 137.445 MiB, 4.90% gc time, 23.61% compilation time)

```

Also, the argument name `defaultpath` should probably change, since from a user perspective this is the argument to use so that you simply set the file path and could be confusing to call it `defaultpath`. Simply, calling it `path` is probably enough.  
@giordano And what makes me wonder apart from the time difference is why you have so much less fewer allocations in linux. But I guess these are purely due to internal os differences…

---

<div class="post-metadata">

**Author:** ![suavesito](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/suavesito/32/34386_2.png) [@suavesito](https://discourse.julialang.org/u/suavesito)\
**Post date:** [October 16, 2021, 1:51pm UTC](https://discourse.julialang.org/t/file-choose-in-julia/69703/58 "2021-10-16T13:51:31Z")

</div>

> [@rafael.guerra](#):
>
> The parameter `filterlist` despite of its name does not seem to accept multiple filters (like Gtk does)?

The format for multiples filters is “filter1;filter2”, in a single filter you can add up multiple file types as “ft1\_filter1,ft2\_filter1,ft3\_filter1;ft1\_filter2” etc. I need to add that in the README.

> [@rafael.guerra](#):
>
> - `defaultpath` should probably be defined consistently in all functions as an optional keyword argument?

Will do, I though it was already this way.

---

<div class="post-metadata">

**Author:** ![suavesito](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/suavesito/32/34386_2.png) [@suavesito](https://discourse.julialang.org/u/suavesito)\
**Post date:** [October 16, 2021, 1:56pm UTC](https://discourse.julialang.org/t/file-choose-in-julia/69703/59 "2021-10-16T13:56:05Z")

</div>

> [@suavesito](#):
>
> I guess that time is okay and i don’t need to worry too much about it for now.

For what I see maybe I can save a little bit of time with precompilation, need to do that later.

---

<div class="post-metadata">

**Author:** ![suavesito](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/suavesito/32/34386_2.png) [@suavesito](https://discourse.julialang.org/u/suavesito)\
**Post date:** [October 16, 2021, 1:57pm UTC](https://discourse.julialang.org/t/file-choose-in-julia/69703/60 "2021-10-16T13:57:03Z")

</div>

> [@Alex\_Tantos](#):
>
> Also, the argument name `defaultpath` should probably change, since from a user perspective this is the argument to use so that you simply set the file path and could be confusing to call it `defaultpath` . Simply, calling it `path` is probably enough.

I guess that make sense, will change it. 🙂

---

<div class="post-metadata">

**Author:** ![suavesito](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/suavesito/32/34386_2.png) [@suavesito](https://discourse.julialang.org/u/suavesito)\
**Post date:** [October 19, 2021, 12:33am UTC](https://discourse.julialang.org/t/file-choose-in-julia/69703/61 "2021-10-19T00:33:13Z")

</div>

[Done!](https://github.com/JuliaRegistries/General/pull/46997) 🥳 Now to wait the 3 day period till auto-merge. Any issues or commentaries are welcomed in the [issues section](https://github.com/Suavesito-Olimpiada/NativeFileDialog.jl/issues).

[Previous page](https://discourse.julialang.org/t/file-choose-in-julia/69703.md?page=2)

[Next page](https://discourse.julialang.org/t/file-choose-in-julia/69703.md?page=4)
