caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Reading directory Problem
@ 2003-07-30 18:37 Le, To Trinh
  2003-07-30 19:16 ` Chris Uzdavinis
  0 siblings, 1 reply; 3+ messages in thread
From: Le, To Trinh @ 2003-07-30 18:37 UTC (permalink / raw)
  To: caml-list

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;
 
I  do not know how to check if it is directory the we go to next level.


Thank you

ToTrinh Le



-------------------
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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] Reading directory Problem
  2003-07-30 18:37 [Caml-list] Reading directory Problem Le, To Trinh
@ 2003-07-30 19:16 ` Chris Uzdavinis
  2003-07-30 20:52   ` David Brown
  0 siblings, 1 reply; 3+ messages in thread
From: Chris Uzdavinis @ 2003-07-30 19:16 UTC (permalink / raw)
  To: caml-list

"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...

Ocaml has a function called "stat" (in the Unix module) that can give
you this information.  Who knows, maybe the stat function is available
in the POSIX spec too, with a C interface.  It seems that the POSIX
people copied the OCAML "Unix" library fairly closely.  <g>

-- 
Chris

-------------------
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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] Reading directory Problem
  2003-07-30 19:16 ` Chris Uzdavinis
@ 2003-07-30 20:52   ` David Brown
  0 siblings, 0 replies; 3+ messages in thread
From: David Brown @ 2003-07-30 20:52 UTC (permalink / raw)
  To: Chris Uzdavinis; +Cc: caml-list

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-07-30 20:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-30 18:37 [Caml-list] Reading directory Problem Le, To Trinh
2003-07-30 19:16 ` Chris Uzdavinis
2003-07-30 20:52   ` David Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).