我想要编写一个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
函数需要一个目录作为参数。 - stusmith-fwarn-unused-matches
会忽略以下划线开头的名称。 - hammar