[Haskell-cafe] File path programme

Krasimir Angelov kr.angelov at gmail.com
Tue Jan 25 06:32:29 EST 2005


Hello, Guys

The System.FilePath might not be perfect and might not handle some
unusual cases very well. Most of functions in this module are
collected from Cabal/Alex/Happy/Haddock. Some of these tools already
use their own functions for file path handling. Special care was taken
to make them more portable but probably there is still enough room for
optimizations.

>> What about splitFileExt "foo.bar."? ("foo", "bar.") or ("foo.bar.", "")?
>
> The latter makes more sense to me, as an extension of the first case
> you give and splitting "foo.tar.gz" to ("foo.tar", "gz").

I will take a look at this. I also don't know which case is more natural.

>  (Win32)
>
>  splitFileName "\\\\server\\share" ==> ("\\\\server","share")
>    (should probably be ("\\\\server\\share",""))

Why? "\\\\server" is the server name and "share" is the directory name
on this server.

>  splitFileName "foo:xyz" ==> ("foo:.","xyz")
>    (should be (".","foo:xyz") -- this refers to the named stream
>     xyz of foo)

System.FilePath currently doesn't support NTFS streams. I don't care
much about them because they are rarely used but the things can be
improved. The trouble here is that in some cases the drive letter
cann't be easily distinguished. What does "c:foo" mean, file "foo" on
drive "c" or stream "foo" of file "c"?

>  joinPaths "c:\\" "\\foo" ==> "\\foo"
>    (should be "c:\\foo". I realize that "cd c:\\" on Windows doesn't
>     actually make "c:\\" the current directory, but ";" doesn't
>     separate shell commands either.)

On Windows there is current drive and current directory on each drive.
"\\foo" means top level directory "foo" on the current drive. If the
current drive is "c" then I can agree that the joined path is
"c:\\foo" but if the current drive is "a" then this is wrong. In both
cases "\\foo" is the right answer. If you want something like
"c:\\foo" you can use System.Directory.canonicalizePath.
canonicalizePath "\\foo" returns either "c:\\foo" or "a:\\foo".

>  (Posix)
>
>  splitFileName "/foo" ==> ("/","foo"),
>  splitFileName "/foo/" ==> ("/foo","")
>    (arguably makes sense, but why isn't it documented?)

OK

>  splitFileName "/foo/bar" ==> ("/foo","bar")
>  splitFileName "/foo//bar" ==> ("/foo/","bar")
>    (definitely a bug)

Is "/foo//bar" valid file path and what does "//" mean?

>  pathParents "/foo///bar" ==> ["/","/foo","/foo","/foo","/foo/bar"]

Again what does "///" mean?

>  pathParents "foo/../bar" ==> [".","foo/../bar"]
>    (what if foo doesn't exist and we wanted to create it?)

If "foo" doesn't exist then you can create it or raise an error

Cheers,
  Krasimir


More information about the Haskell-Cafe mailing list