title: Get path and filename of all files in a given dir and its subdirs
body: <p>I was given this code a while back.  I finally got around to testing it (with some changes to put the files in a different place)...</p>
  
  <pre><code>void AddFiles(AnsiString path/*, TDataSet *DataSet*/)
  {
  TSearchRec sr;
  int f;
      f = FindFirst(path+"\\*.*", faAnyFile, sr);
      while( !f )
      {
          if(sr.Attr &amp; faDirectory)
          {
                  if(sr.Name != "."   &amp;&amp;   sr.Name != "..")
                  {
                          path.sprintf("%s%s%s", path, "\\", sr.Name);
                          AddFiles(path/*, DataSet*/);
                  }
          }
          else
          {
                  Form1-&gt;ListBox1-&gt;Items-&gt;Add(path+ "\\"+ sr.Name);
                  //DataSet-&gt;Append();
                  //DataSet-&gt;FieldByName("Name")-&gt;Value = sr.Name;
                  /* other fields ... */
                  //DataSet-&gt;Post();
          }
          f = FindNext(sr);
      }
      FindClose(sr);
  }
  </code></pre>
  
  <p>It doesn't work properly.  In the beginning it gets mixed up..</p>
  
  <p>a real structure of...</p>
  
  <p>root
  root\subdir1
  root\subdir2
  root\subdir3</p>
  
  <p>gets messed up like this...</p>
  
  <p>root
  root\subdir1
  root\subdir1\subdir2
  root\subdir1\subdir2\subdir3</p>
  
  <p>and eventually it stops including the root or sub\sub folders and 'path' just contains a subfolder (without its root folders)</p>
  
  <p>this is completely useless for aquring useable full-path filenames.</p>
  
  <p>so <strong>either</strong> can you tell me where the code is going wrong...  <strong>or</strong> give me some advice on how to get the full path filenames in a dir and all its subdirs.</p>
  
  <p>I want it to be as basic as possible.   i.e. no uncommon advanced c++ features.  stuff that a builder noob is likely to be able to debug.</p>