# Isfile and strings with "?" in 0.7.0 ... workarounds, other than try/catch?

**URL:** <https://discourse.julialang.org/t/isfile-and-strings-with-in-0-7-0-workarounds-other-than-try-catch/13203>\
**Category:** General Usage\
**Created:** [August 10, 2018, 8:46pm UTC](https://discourse.julialang.org/t/isfile-and-strings-with-in-0-7-0-workarounds-other-than-try-catch/13203 "2018-08-10T20:46:31Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![joshua\_jones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joshua_jones/32/7554_2.png) [@joshua\_jones](https://discourse.julialang.org/u/joshua_jones)\
**Post date:** [August 10, 2018, 8:46pm UTC](https://discourse.julialang.org/t/isfile-and-strings-with-in-0-7-0-workarounds-other-than-try-catch/13203/1 "2018-08-10T20:46:31Z")

</div>

I need to test isfile on a string. However, if the string is **not** a filename, it will almost always include question marks. This breaks in Julia 0.7 using Windows 10 Home but not previous versions. MWE below.

v0.6.X:

```julia
julia> str = "E?Z"
"E?Z"

julia> isfile(str)
false

```

v.0.7.0:

```julia
julia> str = "E?Z"
"E?Z"

julia> isfile(str)
ERROR: IOError: stat: invalid argument (EINVAL)
Stacktrace:
 [1] stat(::String) at .\stat.jl:68
 [2] isfile(::String) at .\stat.jl:303
 [3] top-level scope at none:0

```

What changed here? Is there a clean workaround?

I know that I _could_ enclose the test in a try/catch statement, but considering how little overhead a Boolean test should require, this seems like an extremely clumsy and unhygienic kluge.

Thanks in advance for any suggestions.

---

<div class="post-metadata">

**Author:** ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)\
**Post date:** [August 10, 2018, 8:58pm UTC](https://discourse.julialang.org/t/isfile-and-strings-with-in-0-7-0-workarounds-other-than-try-catch/13203/2 "2018-08-10T20:58:53Z")

</div>

Can’t reproduce on Linux:

```julia
               _                                                                                                                                                                                                                                                                
   _ _ _(_)_ | A fresh approach to technical computing                                                                                                                                                                                                               
  (_) | (_) (_) | Documentation: https://docs.julialang.org                                                                                                                                                                                                             
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.                                                                                                                                                                                                                 
  | | | | | | |/ _` | |                                                                                                                                                                                                                                                        
  | | |_| | | | (_| | | Version 0.7.0 (2018-08-08 06:46 UTC)                                                                                                                                                                                                                  
 _/ |\ __'_|_|_|\__'_| | Official http://julialang.org/ release                                                                                                                                                                                                                
|__/ | x86_64-pc-linux-gnu                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                                                
julia> str = "E?Z"
"E?Z"                                                                                                                                                                                                                                                                           
                                                                                                                                                                                                                                                                                
julia> isfile(str)
false

```

What OS are you using?

---

<div class="post-metadata">

**Author:** ![joshua\_jones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joshua_jones/32/7554_2.png) [@joshua\_jones](https://discourse.julialang.org/u/joshua_jones)\
**Post date:** [August 10, 2018, 9:02pm UTC](https://discourse.julialang.org/t/isfile-and-strings-with-in-0-7-0-workarounds-other-than-try-catch/13203/3 "2018-08-10T21:02:05Z")

</div>

Sorry, let me edit that into my post. Windows 10 Home.

---

<div class="post-metadata">

**Author:** ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)\
**Post date:** [August 10, 2018, 9:05pm UTC](https://discourse.julialang.org/t/isfile-and-strings-with-in-0-7-0-workarounds-other-than-try-catch/13203/4 "2018-08-10T21:05:26Z")

</div>

Looks like [https://github.com/JuliaLang/julia/issues/26685](https://github.com/JuliaLang/julia/issues/26685).

---

<div class="post-metadata">

**Author:** ![joshua\_jones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joshua_jones/32/7554_2.png) [@joshua\_jones](https://discourse.julialang.org/u/joshua_jones)\
**Post date:** [August 10, 2018, 9:16pm UTC](https://discourse.julialang.org/t/isfile-and-strings-with-in-0-7-0-workarounds-other-than-try-catch/13203/5 "2018-08-10T21:16:27Z")

</div>

Right, I’m glad that it’s a known issue, but it doesn’t seem resolved yet. Looking at the comments, I see a pull request referencing it, but last comment 13 days ago and developer says “no time to fiddle with it anymore”. It’s not clear whether a I should wait for a fix, use try/catch for now, or do something else.

---

<div class="post-metadata">

**Author:** ![joshua\_jones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joshua_jones/32/7554_2.png) [@joshua\_jones](https://discourse.julialang.org/u/joshua_jones)\
**Post date:** [August 11, 2018, 12:56am UTC](https://discourse.julialang.org/t/isfile-and-strings-with-in-0-7-0-workarounds-other-than-try-catch/13203/6 "2018-08-11T00:56:40Z")

</div>

Perhaps I should ask “is there _any_ workaround”? I just tried the recommended “hack” workaround at [https://github.com/JuliaPackaging/BinaryProvider.jl/commit/08a314a225206a68665c6f730d7c3feeda1ba615](https://github.com/JuliaPackaging/BinaryProvider.jl/commit/08a314a225206a68665c6f730d7c3feeda1ba615) It hung Julia 0.7 and crashed Julia 1.0 in Windows 10, even when I changed “Base.UVError” (which gave a deprecation warning in 0.7) to Base.IOError.

---

<div class="post-metadata">

**Author:** ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)\
**Post date:** [August 11, 2018, 3:06am UTC](https://discourse.julialang.org/t/isfile-and-strings-with-in-0-7-0-workarounds-other-than-try-catch/13203/7 "2018-08-11T03:06:25Z")

</div>

That does seem like a bad situation. Perhaps comment on the issue to remind people in the know; maybe info from ["Session using SocketStream throws ENOENT" test fails with libuv 1.20.3 · Issue #34 · neovim/lua-client · GitHub](https://github.com/neovim/lua-client/issues/34) (which linked to the Julia issue and is closed) can help fix it.

---

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [August 11, 2018, 3:50am UTC](https://discourse.julialang.org/t/isfile-and-strings-with-in-0-7-0-workarounds-other-than-try-catch/13203/8 "2018-08-11T03:50:23Z")

</div>

It seems like what is happening is that Julia is passing the string to some Windows API and that API throws an error when it encounters a question mark. If that’s indeed the case that would make this a Windows issue rather than a Julia issue.

In the meantime, this is no better than `try` `catch` I suppose, but you could also do:

```julia
function isfile_windowsisscrewingme(str::AbstractString)
    findfirst("?", str) ≡ nothing && isfile(str)
end 

```

---

<div class="post-metadata">

**Author:** ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)\
**Post date:** [August 11, 2018, 4:07am UTC](https://discourse.julialang.org/t/isfile-and-strings-with-in-0-7-0-workarounds-other-than-try-catch/13203/9 "2018-08-11T04:07:09Z")

</div>

While the issue is Windows-specific, it seems to be a mismatch between a change in libuv and Julia’s usage of libuv that caused this, so it seems unfair to blame Windows. (note that I haven’t been a Windows user for 6 years).

---

<div class="post-metadata">

**Author:** ![joshua\_jones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joshua_jones/32/7554_2.png) [@joshua\_jones](https://discourse.julialang.org/u/joshua_jones)\
**Post date:** [August 11, 2018, 6:15am UTC](https://discourse.julialang.org/t/isfile-and-strings-with-in-0-7-0-workarounds-other-than-try-catch/13203/10 "2018-08-11T06:15:25Z")

</div>

Thank you both for the suggestions; ExpandingMan’s suggestion is working for now. tkoolen, I’m with you on Windows; I don’t use it by choice, and never for research. Nevertheless, it has many adherents, and I’ve found that trying to convince career researchers to switch operating systems takes more effort than coding the occasional workaround…
