{
  "id": "1998-october-means-to-appends",
  "slug": "1998-october-means-to-appends",
  "url": "https://dwillis.github.io/uplink/article/1998-october-means-to-appends.html",
  "year": 1998,
  "month": "October",
  "monthNum": 10,
  "headline": "Means to appends",
  "kicker": "TECH TIP",
  "author_name": "Justin Mayo",
  "author_title": "Data Manager",
  "affiliation": "NICAR",
  "summary": "NICAR journalists developed a FoxPro solution using the ADIR() function to efficiently append hundreds of identically structured database tables into a single dataset, avoiding repetitive manual work and demonstrated this approach with USDA meat-packing inspection data split across nearly 800 regional files.",
  "keywords": [
    "FoxPro",
    "database",
    "automation"
  ],
  "topics": [
    "Data & Databases",
    "Technology",
    "Investigative Methods"
  ],
  "technologies": [
    "FoxPro",
    "dBase",
    "CD-ROM"
  ],
  "full_text": "Have you ever had to append hundreds of tables together? At NICAR we were faced with such a repetitive task often enough that we came up with a programming solution. Rather than permanently disfiguring ourselves with carpal tunnel syndrome, we turned to one favorite data-processing FoxPro functions-ADIR().\n\nThe ADIR() function makes use of arrays. An array can be thought of as a temporary table. In the case of ADIR(), a temporary array is made up of the contents of a specified directory on your computer. Five pieces of file information are included in an ADIR() array: names, sizes, dates, times and attributes. This information makes up the columns in the array, but the most important for our purposes is the file name. Here's an example of how ADIR() can save your sanity.\n\nWhen we processed the USDA meat-packing inspections database, ADIR() was indispensable. The meat-packing data arrived on a CD-ROM in dBase format but were separated into nearly 800 identically structured tables, broken down by the region. What we wanted, however, was one table for the entire country. Here's what the basic code that appended the USDA tables looked like:\n\ngcOutputDir = 'c:\\usda\\outgoing\\'\ngcSourceDir = 'c:\\usda\\incoming\\'\nUSE (gcOutputDir) + 'all_usda.dbf' in 1\n=ADIR(temparray, (gcSourceDir) + '*.dbf')\nSELECT 1\nFOR i = 1 to ALEN(temparray, 1)\nAPPEND FROM (gcSourceDir) + (temparray(i,1))\nENDFOR\n\nExplaining the code\n\nThe first two lines of the above code simply set our working directories. The source tables are in the incoming directory. The outgoing directory contains an empty table structure - all_usda.dbf - that will become the USDA database for the entire country. (NOTE: This code assumes that the structures of your individual source tables are the same. If not, you could lose data when you append them.)\n\nThe third line opens the table structure (all_usda.dbf) into which we will be appending.\n\nThe fourth line is where ADIR() comes into play. The function can handle up to three arguments, though in this case we only use two: temparray and gcSourceDir + '*.dbf'\n\nThe first argument (temparray) is simply the name of the array that will contain the file names, sizes, dates, times and attributes. In this example, the array did not exist, so FoxPro created one that we named temparray. If the array did exist, FoxPro would have modified the size of the array so that the information would fit.\n\nThe second argument (gcSourceDir + '*.dbf') tells FoxPro to look in the source directory and put all the files with a .dbf extension into our array. With all of the file names and attributes stored in this temporary array, we are ready to append the source tables into the outgoing table.\n\nIn the fifth line, we select the outgoing table (all_usda.dbf). Next, we need to tell the program to go through the array one row (or one file name) at a time. This is why the FOR ENDFOR loop is used. In the loop, the 'i' is the counter variable that keeps the loop going. So that it begins with the first file name in the array, we set it to 1. (ALEN(temparray, 1)) tells FoxPro to continue the loop until it hits the end of the array. The '1' in the ALEN function makes sure that we are counting the number of rows in the array (which will be the same as the number of file names).\n\nFinally, in the seventh line, we append the source tables into the outgoing table (all_usda.dbf). The last part of that line - (temparray(i,1)) - is important. The (i,1) singles out the first column in temparray, which, in the case of an ADIR() array, will always be the name of the file. As we loop through the array, we are telling FoxPro to keep appending the source tables until it reaches the end of the array.\n\nJustin Mayo can be reached by email at justin@nicar.org.",
  "provenance": {
    "extracted_by": "anthropic/claude-sonnet-4-6",
    "extracted_at": "2026-07-05",
    "verified": true
  },
  "similar": [
    {
      "slug": "1997-may-cheating-at-foxpro",
      "score": 0.215
    },
    {
      "slug": "1997-april-foxpro-wrote-me-a-letter",
      "score": 0.185
    },
    {
      "slug": "1998-april-foxpro-to-access-and-back-again",
      "score": 0.171
    },
    {
      "slug": "1998-march-cleaning-tables",
      "score": 0.144
    },
    {
      "slug": "1997-january-use-foxpro-to-document-a-table",
      "score": 0.142
    }
  ],
  "html_url": "https://dwillis.github.io/uplink/article/1998-october-means-to-appends.html",
  "json_url": "https://dwillis.github.io/uplink/article/1998-october-means-to-appends.json"
}