[Haskell-cafe] os.path.expanduser analogue

Ben Gamari bgamari.foss at gmail.com
Mon Nov 21 02:36:35 CET 2011


On the whole, the filepath package does an excellent job of providing
basic path manipulation tools, one weakness is the inability to resolve
"~/..." style POSIX paths. Python implements this with
os.path.expanduser. Perhaps a similar function might be helpful in
filepath?

Cheers,

- Ben

Possible (but untested) implementation
expandUser :: FilePath -> IO FilePath
expandUser p = if "~/" `isPrefixOf` p
                  then do u <- getLoginName
                          return $ u ++ drop 2 p
                  else return p



More information about the Haskell-Cafe mailing list