import System.Directory
import qualified Data.ByteString as BS
import qualified Data.ByteString.UTF8 as BS_UTF8
main = do
putStrLn "Input path to some file: "
raw_inputed_path <- BS.getLine
let inputed_path = BS_UTF8.toString raw_inputed_path
such_file_exists <- doesFileExist inputed_path
such_directory_exists <- doesDirectoryExist inputed_path
if such_file_exists
then putStrLn "Yeah, I see it!"
else if such_directory_exists
then putStrLn "Aha, I see it, but it's a directory!"
else putStrLn "Hmm... No such..."
This code perfectly works with ASCII-paths only. But if I use paths with non-ASCII symbols, doesFileExist and doesDirectoryExist always return False. Why?
- Debian GNU/Linux 6.0 x86_64
- ghc 6.12.1
Upgrade to GHC 7.x series – 6.12 is now nearly 3 years out of date. The behavior was fixed around a year ago.