# Convert filepath to URI

**URL:** <https://discourse.julialang.org/t/convert-filepath-to-uri/123334>\
**Category:** New to Julia\
**Created:** [December 2, 2024, 12:54am UTC](https://discourse.julialang.org/t/convert-filepath-to-uri/123334 "2024-12-02T00:54:16Z")\
**Posts on this page:** 1\
**Showing post:** 4

<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:** [December 2, 2024, 1:40am UTC](https://discourse.julialang.org/t/convert-filepath-to-uri/123334/4 "2024-12-02T01:40:07Z")

</div>

See [What to use for URL encoding? - #3 by quinnj](https://discourse.julialang.org/t/what-to-use-for-url-encoding/25467/3) — ~~the HTTP.jl package~~ the URIs.jl package has a function `escapeuri` to escape strings for URIs. It won’t convert backslash to forward slashes, but you can apply it to _each component_ of the path (via `splitpath`, which splits by `\` on Windows) to escape special characters like spaces. In particular, you can define the function:

```julia
import URIs
path2uri(path) = "file://" * join(map(URIs.escapeuri, splitpath(path)), '/')

```

and apply it to convert your path to a `file://` URI.

(It might be nice to have a function like this in the URIs.jl package if someone feels like ~~filing an issue or~~ making a PR for the issue: [filepath2uri function? · Issue #61 · JuliaWeb/URIs.jl · GitHub](https://github.com/JuliaWeb/URIs.jl/issues/61))

---

_[View the full topic](https://discourse.julialang.org/t/convert-filepath-to-uri/123334)._
