caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: David Brown <caml-list@davidb.org>
To: Chris Uzdavinis <chris@atdesk.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Reading directory Problem
Date: Wed, 30 Jul 2003 13:52:56 -0700	[thread overview]
Message-ID: <20030730205256.GA28673@davidb.org> (raw)
In-Reply-To: <j61xw7hljt.fsf@explicit.atdesk.com>

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


      reply	other threads:[~2003-07-30 20:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-30 18:37 Le, To Trinh
2003-07-30 19:16 ` Chris Uzdavinis
2003-07-30 20:52   ` David Brown [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030730205256.GA28673@davidb.org \
    --to=caml-list@davidb.org \
    --cc=caml-list@inria.fr \
    --cc=chris@atdesk.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).