1
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. 为什么?

  • Debian GNU/Linux 6.0 x86_64
  • ghc 6.12.1
4

1 回答 1

2

升级到 GHC 7.x 系列 - 6.12 现在已经过时了将近 3 年。该行为大约在一年前得到修复。

于 2012-04-26T11:42:53.493 回答