Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Reading directory Problem
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-07-30 (20:53)
From: David Brown <caml-list@d...>
Subject: Re: [Caml-list] Reading directory Problem
On Wed, Jul 30, 2003 at 03:16:54PM -0400, Chris Uzdavinis wrote:
> "Le, To Trinh" <> writes:
> > Hello,
> >
> > I have problem with determine directory or file type.  I wrote 
> > DIR * dirp; struct dirent *pDirent; 
> > while((pDirent=readdir(dirp)) != NULL)
> > {
> > if(pDirent->d_name[0] == '.'  continue;
> This isn't a C newsgroup... but...

The code is also incorrect, in that it only compares the first character
of the name with '.'.  Better to compare the whole string against "."
and "..".  The code given will discard any filenames that start with
'.', which is definitely not what you want.

The Unix library contains both stat and lstat.  Lstat is useful if you
want to see symlinks as symlinks.  This is ususally useful when writing
archiving or other types of operations.  stat will just show you the
type of what a symlink targets.

BTW, if you are recursively reading directories, you should opendir,
readdir, and closedir and entire directory before going on to the next.
Ocaml makes it very easy to put the results into a list.  There is a
fixed number open file handles that are permitted, so nesting the
opendirs will fail in the general case.


To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: