Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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" <tle@filenet.com> 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.

Dave

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners