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

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.


julia> str = "E?Z"

julia> isfile(str)


julia> str = "E?Z"

julia> isfile(str)
ERROR: IOError: stat: invalid argument (EINVAL)
 [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.

Can’t reproduce on Linux:

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

What OS are you using?

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

Looks like

1 Like

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.

Perhaps I should ask “is there any workaround”? I just tried the recommended “hack” workaround at 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.

That does seem like a bad situation. Perhaps comment on the issue to remind people in the know; maybe info from (which linked to the Julia issue and is closed) can help fix it.

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:

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

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).

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…