我想要写一个Haskell函数来返回当前目录的文件,例如

将当前目录更改为

 :cd c:/code/haskell

然后编写一个函数返回一组文件,例如
 [x | x <-getDirectoryContents ]

编辑:

我已经写了一个这样的函数列出文件
(参考:http://zvon.org/other/haskell/Outputdirectory/index.html)
import Directory

main = _dir "/tmp/FOO"

_dir _path =do
    setCurrentDirectory _path
    _cd <- getCurrentDirectory
    print _cd
    _file <- getDirectoryContents _cd
    print _file

因此,调用_dir“c:/ code / haskell”将列出所有文件+目录名(非递归)。我现在想要的是在谓词函数中调用此函数,例如:
[ x| x <- _dir  "c:/code/haskell" | x start with 'haskell_' ]

所以我可以对文件名应用过滤器

最佳答案

看来您正在寻找:

getDirectoryContents :: FilePath -> IO [FilePath]

参考:http://www.haskell.org/ghc/docs/6.12.2/html/libraries/directory-1.0.1.1/System-Directory.html#1

10-02 07:19
查看更多