[Haskell-cafe] [Beginner's Question] How to read filenames from a
DirStream
Alec Berryman
alec at thened.net
Sun Apr 8 23:11:23 EDT 2007
Albert Lee on 2007-04-09 10:46:14 +0800:
> I want to ls the filenames of a directory.
[...]
> and I write that in haskell:
>
> -----
> import System.Posix
> import System.IO
>
> main = do
> dp <- openDirStream "/"
> df <- readDirStream dp
> putStrLn df
> closeDirStream dp
>
>
> ------
> It can print the first entry of the dir, but how can we list it all like the
> C prog? map ? list comperhension?
System.Posix is one way to do it, but you might find the functions in
System.Directory easier to use - there's a function to get the
directory contents as a list of strings. To print them out, you may
want to look at one of the mapM functions.
More information about the Haskell-Cafe
mailing list