How can I list disk drives in Haskell? I would like to get disk drive letters on Windows and get just "/" on Linux. Is it possible? I couldn't find it anywhere.
Asked
Active
Viewed 277 times
7
-
It seems that you want [`GetLogicalDriveStrings`](http://msdn.microsoft.com/en-us/library/aa364975%28VS.85%29.aspx), but it is not wrapped in [`System.Win32.File`](http://hackage.haskell.org/packages/archive/Win32/2.2.2.0/doc/html/System-Win32-File.html). – Joachim Breitner Sep 05 '13 at 10:44
-
Is there any way to do it without Win32? I ask because I can compile it only on windows and I will lose portability... – remdezx Sep 05 '13 at 10:56
-
Not that I know of, and I doubt it. You can use `CPP` pragmas though. – Joachim Breitner Sep 05 '13 at 11:47
-
What do you mean by CPP pragmas? – remdezx Sep 05 '13 at 12:14
-
He means #ifdef conditional compilation directives from C PreProcessor. – nponeccop Sep 05 '13 at 12:47
-
See http://stackoverflow.com/a/6362016/946226 for some discussion of them. – Joachim Breitner Sep 05 '13 at 12:48
-
@JoachimBreitner: That is interesting. Do you have any example? – Wojciech Danilo Sep 05 '13 at 14:44
-
See [https://github.com/jystic/unix-compat/blob/master/src/System/PosixCompat.hs] which uses the predefined flag `mingw32_HOST_OS`. – Joachim Breitner Sep 05 '13 at 18:03
2 Answers
4
import System.Process
c = do
res <- readProcess "wmic" ["logicaldisk","get","caption"] ""
--print res
-- clean up the output
print $ init $ map (take 2) $ drop 1(lines res)

ja.
- 4,245
- 20
- 22
1
You could try just enumerating all 26 possible drive letters and seeing if they exist using doesDirectoryExist
from System.Directory
. I believe that would work...

MathematicalOrchid
- 61,854
- 19
- 123
- 220