<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2003/07/d338fb368c7b031bdc17357384a3ff41"
  from="David Brown &lt;caml-list@d...&gt;"
  author="David Brown"
  date="2003-07-30T20:53:02"
  subject="Re: [Caml-list] Reading directory Problem"
  prev="2003/07/c4e7f06dcc3f5751e6b9381cfc8f437d"
  next="2003/07/2ab0695537c88013248508e26fa5a6f2"
  prev-in-thread="2003/07/c4e7f06dcc3f5751e6b9381cfc8f437d"
  prev-thread="2003/07/cddd71399bc88212fc5edc3659aaa3c5"
  next-thread="2003/07/2ab0695537c88013248508e26fa5a6f2"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] Reading directory Problem">
<msg 
  url="2003/07/f86c532427805fcf15b4d5165f7adfb8"
  from="Le, To Trinh &lt;tle@f...&gt;"
  author="Le, To Trinh"
  date="2003-07-30T18:38:05"
  subject="[Caml-list] Reading directory Problem">
<msg 
  url="2003/07/c4e7f06dcc3f5751e6b9381cfc8f437d"
  from="Chris Uzdavinis &lt;chris@a...&gt;"
  author="Chris Uzdavinis"
  date="2003-07-30T19:17:00"
  subject="Re: [Caml-list] Reading directory Problem">
<msg 
  url="2003/07/d338fb368c7b031bdc17357384a3ff41"
  from="David Brown &lt;caml-list@d...&gt;"
  author="David Brown"
  date="2003-07-30T20:53:02"
  subject="Re: [Caml-list] Reading directory Problem">
</msg>
</msg>
</msg>
</thread>

<contents>
On Wed, Jul 30, 2003 at 03:16:54PM -0400, Chris Uzdavinis wrote:
&gt; "Le, To Trinh" &lt;tle@filenet.com&gt; writes:
&gt; 
&gt; &gt; Hello,
&gt; &gt;
&gt; &gt; I have problem with determine directory or file type.  I wrote 
&gt; &gt; DIR * dirp; struct dirent *pDirent; 
&gt; &gt; while((pDirent=readdir(dirp)) != NULL)
&gt; &gt; {
&gt; &gt; if(pDirent-&gt;d_name[0] == '.'  continue;
&gt; 
&gt; 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

</contents>

</message>

