doesFileExist cannot get ~/blah_blah right

Hi, 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. I do not want to change "~" to a specific home directory such as "/home/a_userid" for the sake of portability. What else can I do before the bug (suppose this is a bug) is fixed? Thanks, Hong

On 8 April 2013 15:45, Hong Yang
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@gmail.com

On Tue, Apr 9, 2013 at 6:04 AM, Erlend Hamberg
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.
To expand on this, doesFileExist is a thin shim over a low-level OS call. On the other hand, tilde expansion happens at the shell (application) level. -- Kim-Ee

On Mon, Apr 08, 2013 at 04:04:22PM -0700, Erlend Hamberg wrote:
On 8 April 2013 15:45, Hong Yang
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
Also, since we are discussing portability, it's a much better idea to do homedir > "blah_blah" instead of homedir ++ "/blah_blah", since the former will use the correct path separator character for whatever system it is compiled on. -Brent

On 04/09/2013 07:07 AM, Brent Yorgey wrote:
Also, since we are discussing portability, it's a much better idea to do
homedir > "blah_blah"
instead of homedir ++ "/blah_blah", since the former will use the correct path separator character for whatever system it is compiled on.
Wait, what? Where'd ">" come from? -- Tommy M. McGuire mcguire@crsr.net

There is a package system-filepath
http://hackage.haskell.org/package/system-filepath which fixes a lot of
quibbles people have with the way filepaths are implemented in haskell.
There are apparently a lot of problems with using strings as filepaths,
like the fact that they are slow, that they have encoding issues, and that
people cannot make a path that is system agnostic.
So the > operator in that library just joins two filepaths together with
the correct slash.
On Tue, Apr 9, 2013 at 12:15 PM, Tommy M. McGuire
On 04/09/2013 07:07 AM, Brent Yorgey wrote:
Also, since we are discussing portability, it's a much better idea to do
homedir > "blah_blah"
instead of homedir ++ "/blah_blah", since the former will use the correct path separator character for whatever system it is compiled on.
Wait, what? Where'd ">" come from?
-- Tommy M. McGuire mcguire@crsr.net
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

On Tue, Apr 09, 2013 at 12:25:10PM -0400, David McBride wrote:
There is a package system-filepath http://hackage.haskell.org/package/system-filepath which fixes a lot of quibbles people have with the way filepaths are implemented in haskell. There are apparently a lot of problems with using strings as filepaths, like the fact that they are slow, that they have encoding issues, and that people cannot make a path that is system agnostic.
So the > operator in that library just joins two filepaths together with the correct slash.
This is all true, though using system-filepath is still annoying to use because it doesn't play well with everything else in the Haskell ecosystem. However, I was not referring to the (>) in system-filepath but rather the one in the standard 'filepath' package. -Brent

I didn't even know the standard library had a > operator. Here's to
learning new things.
On Tue, Apr 9, 2013 at 8:06 PM, Brent Yorgey
There is a package system-filepath http://hackage.haskell.org/package/system-filepath which fixes a lot of quibbles people have with the way filepaths are implemented in haskell. There are apparently a lot of problems with using strings as filepaths, like the fact that they are slow, that they have encoding issues, and
On Tue, Apr 09, 2013 at 12:25:10PM -0400, David McBride wrote: that
people cannot make a path that is system agnostic.
So the > operator in that library just joins two filepaths together with the correct slash.
This is all true, though using system-filepath is still annoying to use because it doesn't play well with everything else in the Haskell ecosystem. However, I was not referring to the (>) in system-filepath but rather the one in the standard 'filepath' package.
-Brent
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

Neither did I. (And I keep forgetting about hoogle. Sorry.) Thanks! On 04/09/2013 08:19 PM, David McBride wrote:
I didn't even know the standard library had a > operator. Here's to learning new things.
On Tue, Apr 9, 2013 at 8:06 PM, Brent Yorgey
mailto:byorgey@seas.upenn.edu> wrote: On Tue, Apr 09, 2013 at 12:25:10PM -0400, David McBride wrote: > There is a package system-filepath > http://hackage.haskell.org/package/system-filepath which fixes a lot of > quibbles people have with the way filepaths are implemented in haskell. [...]
This is all true, though using system-filepath is still annoying to use because it doesn't play well with everything else in the Haskell ecosystem. However, I was not referring to the (>) in system-filepath but rather the one in the standard 'filepath' package.
-Brent
_______________________________________________ Beginners mailing list Beginners@haskell.org mailto:Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
-- Tommy M. McGuire mcguire@crsr.net

Hi Tommy, On Tue, Apr 09, 2013 at 11:15:01AM -0500, Tommy M. McGuire wrote:
Wait, what? Where'd ">" come from?
hoogle or hayoo are great for answering such question, just try searching for > . It's from: http://hackage.haskell.org/package/filepath Greetings, Daniel
participants (7)
-
Brent Yorgey
-
Daniel Trstenjak
-
David McBride
-
Erlend Hamberg
-
Hong Yang
-
Kim-Ee Yeoh
-
Tommy M. McGuire