Issue
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.
Solution
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).
Answered By - amalloy Answer Checked By - Cary Denson (WPSolving Admin)