title: Visual FoxPro Compact Index File Format
body: <p>I am trying to understand the file format of a Visual FoxPro compact index (*.IDX). I am currently referring to <a href="http://msdn.microsoft.com/en-us/library/s8tb8f47(VS.80).aspx" rel="nofollow noreferrer">Microsoft's documentation</a> for guidance.</p>
  
  <p>The index is a B-tree of 512-byte nodes. Each leaf ("exterior") node contains multiple entries. Each entry consists of four pieces of data:</p>
  
  <ul>
  <li>Row number [FIXED LENGTH]</li>
  <li>Duplicate byte count (documentation doesn't explain this) [FIXED LENGTH]</li>
  <li>Trailing byte count (documentation doesn't explain this) [FIXED LENGTH]</li>
  <li>Key [VARIABLE LENGTH]</li>
  </ul>
  
  <p>The entries (without their keys) are stored at the beginning of the node, immediately after the node's 24-byte header. Their keys are not included at this location because the keys vary in length, while the row number, duplicate byte count and trailing byte counts are fixed in length. The keys are stored at the end of the node and work their way backward. For example:</p>
  
  <ul>
  <li>24 byte header</li>
  <li>row number, duplicate byte count, trailing byte count (entry #1)</li>
  <li>row number, duplicate byte count, trailing byte count (entry #2)</li>
  <li>row number, duplicate byte count, trailing byte count (entry #3)</li>
  <li>...</li>
  <li>key (entry #3)</li>
  <li>key (entry #2)</li>
  <li>key (entry #1)</li>
  </ul>
  
  <p>How do I determine the individual lengths of the keys? The documentation does not appear to specify this. They are perfectly contiguous (no null-byte separators).</p>
  
  <p>I can isolate the keys manually by visual inspection. I suspected that the trailing byte count represented the length of the key. However, it did not correlate to the lengths determined by this inspection.</p>
  
  <p>I believe that the FoxPro file formats are derived from the xBase standard. Perhaps this rings a bell?</p>