I replaced this code with a call to `GetFileAttributes()`. If the call succeeds, we can safely assume it is a valid filename :-)