Adding a file to a node programatically
I think from what I understand; you are trying to add each file(s) to its node folder public://results/[nid]/filename.ext

As solution to your issue, first you need to save the node before you attach the file(s) to it. Then move/save file(s) to its desired location. Then attach the moved file(s) to the selected node again.

Change your code to look like the following:

$result = new stdClass;
$result-&gt;type = "results";
node_object_prepare($result);

//add values to text fields here

// save node
node_save($result);


//open the source directory

$d = dir($seasonDir);

while(false !== ($entry = $d-&gt;read())) {
  if($entry != "." &amp;&amp; $entry != "..") {

    $dir = 'public://results/' . $result-&gt;nid;  
    // create folder str 
    if(file_prepare_directory($dir, FILE_CREATE_DIRECTORY)) {

      //set the file location
      $fileLocation = $seasonDir . "/" . $entry;

      //get the file contents
      $fileContents = file_get_contents($fileLocation);

      //save the file - added nid as sub folder
      $file = file_save_data($fileContents, $dir . '/' . $entry, FILE_EXISTS_RENAME);

      // important if you are importing none image files
      $file-&gt;display = 1; 

      // you don't need to copy files to an array anymore

      // create entity object to store file(s) to the node 

      $entity = new stdClass();
      $entity-&gt;nid = $result-&gt;nid;
      $entity-&gt;vid = $result-&gt;vid;
      $entity-&gt;type  = $result-&gt;type;

      //create an array to assign to the various file fields
      $file_details = array(LANGUAGE_NONE =&gt; array('0' =&gt; (array)$file));

      switch($entry) {
        case "results.inc.html":
          $entity-&gt;field_results_html = $file_details;
          break;
        case"clubs.inc.html":
          $entity-&gt;field_clubs_html = $file_details;
          break;
        case "events.inc.html":
          $entity-&gt;field_events_html = $file_details;
          break;
        case "index.xml":
          $entity-&gt;field_results_index = $file_details;
          break;
        case "events.xml":
          $entity-&gt;field_results_events = $file_details;
          break;
        case "clubs.xml":
          $entity-&gt;field_results_clubs = $file_details;
          break;
        case "results.xml":
          $entity-&gt;field_results = $file_details;
          break;
        default:
          //because the resuls_files field allows multiple files, this
          //field has to use a different method of assigning the file
          $entity-&gt;results_files[LANGUAGE_NONE][] = (array)$file;
          break;
      }

      // save entity 
      field_attach_presave('node', $entity);
      field_attach_update('node', $entity);
    }
  }
}
$d-&gt;close();