【问题标题】:Haskell list drives in WindowsHaskell 列出 Windows 中的驱动器
【发布时间】:2013-09-05 09:51:11
【问题描述】:

如何在 Haskell 中列出磁盘驱动器?我想在 Windows 上获取磁盘驱动器号,在 Linux 上只获取“/”。是否可以?我在任何地方都找不到它。

【问题讨论】:

  • 好像你想要GetLogicalDriveStrings,但是没有包裹在System.Win32.File中。
  • 没有Win32有什么办法吗?我问是因为我只能在 Windows 上编译它,我会失去可移植性......
  • 我不知道,我对此表示怀疑。不过,您可以使用 CPP 编译指示。
  • CPP 编译指示是什么意思?
  • 他的意思是来自 C PreProcessor 的 #ifdef 条件编译指令。

标签: windows haskell


【解决方案1】:
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)

【讨论】:

  • 这就是我想要的!谢谢!
【解决方案2】:

您可以尝试使用来自System.DirectorydoesDirectoryExist 枚举所有26 个可能的驱动器号并查看它们是否存在。我相信会奏效...

【讨论】:

    猜你喜欢
    • 2013-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-20
    • 1970-01-01
    相关资源
    最近更新 更多