schuelermine
schuelermine

Reputation: 2288

Is there a platform-independent way to check if a file path is some representation of a root directory in Haskell?

In Haskell, is there a portable way to check of a FilePath if it’s a root directory, e.g. / or // on Unix/POSIX/Linux, and C:\ or \\?\UNC\Foobar on Windows/NT/DOS? I’ve checked through the directory and filepath packages but I can’t find a function for this.

Upvotes: 0

Views: 413

Answers (1)

amalloy
amalloy

Reputation: 92047

I don't see anything in base, but there appears to be a filepath library that claims to be shipped with GHC (and indeed I find it available even in a project with no dependencies). It contains functions such as isDrive :: FilePath -> Bool. It notes that on POSIX, / is considered the only "drive". This function appears to behave the way you hope (scroll up to the docs for splitDrive for examples involving UNC).

Upvotes: 4

Related Questions