Add bootstrap.inc to file to programatically save nodes In Drupal 6 I would add these two lines to my code so that I could programatically import fields without having to create a module for it

require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);


However, trying to do this in D7, I am getting all types of errors from defined constants not being defined.  What is the proper way to do this in d7?

I have my script ready, and I do not want to spend another several hours writing code just so this can fit nicely into drupal as a module.  Thoughts? thanks!
Drupal 7 uses the DRUPAL_ROOT constant that is set to the Drupal root directory path. If you look at the code of the index.php file, you will notice the following code.

/**
 * Root directory of Drupal installation.
 */
define('DRUPAL_ROOT', getcwd());

require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
menu_execute_active_handler();


The constant is also used from Drupal functions, such as module_load_include().

  if (function_exists('drupal_get_path')) {
    $file = DRUPAL_ROOT . '/' . drupal_get_path('module', $module) . "/$name.$type";
    if (is_file($file)) {
      require_once $file;
      return $file;
    }
  }


If you have to write, for any reason, a function similar to module_load_include() you should use DRUPAL_ROOT to get the Drupal root directory.

Supposing that in your case Drupal is not in the current directory, you can use the following code.

define('DRUPAL_ROOT', 'the directory containing Drupal');

require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);