# How do I find a type conversion function? PosixPath -\> String

**URL:** <https://discourse.julialang.org/t/how-do-i-find-a-type-conversion-function-posixpath-string/66097>\
**Category:** New to Julia\
**Created:** [August 9, 2021, 10:11pm UTC](https://discourse.julialang.org/t/how-do-i-find-a-type-conversion-function-posixpath-string/66097 "2021-08-09T22:11:54Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![banksiaboy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/banksiaboy/32/27032_2.png) [@banksiaboy](https://discourse.julialang.org/u/banksiaboy)\
**Post date:** [August 9, 2021, 10:11pm UTC](https://discourse.julialang.org/t/how-do-i-find-a-type-conversion-function-posixpath-string/66097/1 "2021-08-09T22:11:55Z")

</div>

I have been starting to use FilePathsBase.jl to manipulate paths, but its PosixPath type is not a subtype of AbstractString.

If I try to open ZipFile.Reader on a PosixPath, it fails because there is no version of ZipFile.Reader() that accepts a PosixPath. That’s a shame, but understandable.

What concerns me is I cannot find a function that converts a PosixPath to a String or other subtype of AbstractString.

I have tried and tried… I’m used to Smalltalk where I have system-wide introspection and inspection. Google doesn’t seem to be my friend.

Haskell has [Hoogle](https://hoogle.haskell.org/) which allows me to search Haskell libraries by type signature: [FilePath → String](https://hoogle.haskell.org/?hoogle=FilePath%20-%3E%20String)

I’d like to search for something like `PosixPath -> AbstractString` which you’d reckon would give me a fighting chance.

The documentation of FilePathsBase says _‘1. Manually convert your path to a string before calling into the package.’_ - without mentioning how to. So maybe it’s obvious to people who already know.

My specific questions:

1. How do I find a function when I need one so obviously?
2. What is the particular function I need for PosixPath → String ?

---

<div class="post-metadata">

**Author:** ![magister-ludi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/magister-ludi/32/4003_2.png) [@magister-ludi](https://discourse.julialang.org/u/magister-ludi)\
**Post date:** [August 9, 2021, 10:30pm UTC](https://discourse.julialang.org/t/how-do-i-find-a-type-conversion-function-posixpath-string/66097/2 "2021-08-09T22:30:16Z")

</div>

This appears to work:

```julia
julia> using FilePathsBase
julia> cwd()
p"C:/some/path"
julia> string(ans)
"C:\\some\\path"
julia> typeof(ans)
String

```

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [August 9, 2021, 10:31pm UTC](https://discourse.julialang.org/t/how-do-i-find-a-type-conversion-function-posixpath-string/66097/3 "2021-08-09T22:31:41Z")

</div>

I don’t know this package, but the first things I would try are `String(path)` and `string(path)`, and see what comes out of it.

In general, if you want to convert value `x` to type `T`, you should try `T(x)` and `convert(T, x)`. No idea if it will work in this case, though.

---

<div class="post-metadata">

**Author:** ![banksiaboy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/banksiaboy/32/27032_2.png) [@banksiaboy](https://discourse.julialang.org/u/banksiaboy)\
**Post date:** [August 9, 2021, 10:43pm UTC](https://discourse.julialang.org/t/how-do-i-find-a-type-conversion-function-posixpath-string/66097/4 "2021-08-09T22:43:55Z")

</div>

Thanks very much - I tried String(path). I’m not sure of the idioms yet.  
I still think we need `joogle.julia.org` did you look at the link for the search `FilePath -> String` on Hoogle? It makes so much sense with a good type system.

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [August 9, 2021, 10:53pm UTC](https://discourse.julialang.org/t/how-do-i-find-a-type-conversion-function-posixpath-string/66097/5 "2021-08-09T22:53:16Z")

</div>

I’m sure a good search engine would very nice. But in this case you shouldn’t ask “How do I find out about operations mapping type A to type B?”, but “How do I convert a value to a type?” in which case the answer presents itself immediately: `convert`.

The above may not be completely clear. Try to think in terms of “what generic operation do I want to perform?” instead of “What can I do with this type?” The focus should be on (generic) functions and what they do, more than on the types they operate on. A shift of perspective, one might say.

---

<div class="post-metadata">

**Author:** ![banksiaboy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/banksiaboy/32/27032_2.png) [@banksiaboy](https://discourse.julialang.org/u/banksiaboy)\
**Post date:** [August 9, 2021, 11:09pm UTC](https://discourse.julialang.org/t/how-do-i-find-a-type-conversion-function-posixpath-string/66097/6 "2021-08-09T23:09:48Z")

</div>

Thanks for your reply! A search would indeed be very nice.

`convert` presents itself to to those who already know. My question `1.` was more general. Trial-and-error is not what I’m really asking for. Conversion is a special-case of the problem. I’m really hunting for a more general answer.

Looking at the output of my failed attempt at conversion. The compiler did a search, but only in my environment:

```julia
MethodError: no method matching String(::PosixPath)
Closest candidates are:
  String(::String) at boot.jl:350
  String(::Vector{UInt8}) at strings/string.jl:53
  String(::Symbol) at strings/string.jl:83
  ...

```

If it had looked in a registry (I think the term is), couldn’t there have been a better result? And… If I could have searched for `PosixPath -> AbstractString` would a such a specialized search be able to have found `string(::PosixPath)`?

---

<div class="post-metadata">

**Author:** ![banksiaboy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/banksiaboy/32/27032_2.png) [@banksiaboy](https://discourse.julialang.org/u/banksiaboy)\
**Post date:** [August 9, 2021, 11:12pm UTC](https://discourse.julialang.org/t/how-do-i-find-a-type-conversion-function-posixpath-string/66097/7 "2021-08-09T23:12:56Z")

</div>

Am I asking part `1` of my question in the right place?

I’m getting practical answers to my concrete problem - and can get on with my lowly hacking…

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [August 9, 2021, 11:24pm UTC](https://discourse.julialang.org/t/how-do-i-find-a-type-conversion-function-posixpath-string/66097/8 "2021-08-09T23:24:16Z")

</div>

I’m also trying to make a more general point here, not just fix the concrete problem. I replied in the parallel thread, but, briefly, I’m suggesting a different approach to searching for solutions, based on _what_ you want to do rather than what you want to do it _to_. In this particular case I made a guess, right or wrong, but I’m trying to be more general.

And, again, I’m not rejecting the search engine idea.
