[Haskell-beginners] doesFileExist cannot get ~/blah_blah right
Erlend Hamberg
ehamberg at gmail.com
Tue Apr 9 01:04:22 CEST 2013
On 8 April 2013 15:45, Hong Yang <hyangfji at gmail.com> wrote:
> I got "not exists ..." from
>
> fileExists <- doesFileExist "~/blah_blah"
> if fileExists then print "exists ..."
> else print "not exists ..."
>
> using the directory-1.1.0.2 package, when ~/blah_blah does exist.
>
When you type “~/blah_blah” in your shell, the *shell* will expand “~” to
your home directory, so when you pass “~/foo” to a program, that program
never sees “~/foo”, but “/home/user/foo”. In other words, “~/blah_blah”
probably does *not* exist.
What you probably should do is to find the user's home directory and
prepend that to “blah_blah”. You can find a user's homedir by calling
`getHomeDirectory` from `System.Directory`:
Prelude System.Directory> homedir <- getHomeDirectory
Prelude System.Directory> putStrLn $ homedir ++ "/blah_blah"
/Users/ehamberg/blah_blah
--
Erlend Hamberg
ehamberg at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130408/55b30c89/attachment.htm>
More information about the Beginners
mailing list