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..."
此代码仅适用于ASCII路径。但是,如果我使用带有非ASCII符号的路径,则doesFileExist
和doesDirectoryExist
始终返回False
。为什么呢?
答案 0 :(得分:2)
升级到GHC 7.x系列 - 6.12现在已经过时了近3年。这种行为是在一年前修复的。