[Haskell-cafe] [Beginner's Question] How to read filenames from a DirStream

Albert Lee hanzhupeng at gmail.com
Sun Apr 8 22:46:14 EDT 2007

Newbie's question: I want to ls the filenames of a directory. The program in
C is something like:

#include <direnet.h>

int main(){
   DIR  *dp;
   struct dirent *dirp;

   dp = opendir("/");

   while((dirp = readdir(dp)) != NULL)
       printf("%s\n", dirp->d_name);


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?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20070409/c21acb5f/attachment.htm

More information about the Haskell-Cafe mailing list