diff --git a/imagecache.drush.inc b/imagecache.drush.inc
index 63dff6c..9e34123 100644
--- a/imagecache.drush.inc
+++ b/imagecache.drush.inc
@@ -99,6 +99,15 @@ function imagecache_drush_preset_flush() {
 function imagecache_drush_preset_build() {
   $args = func_get_args();
 
+  // Change the running dir.
+  $root = drush_get_context('DRUSH_DRUPAL_ROOT');//array_pop($args);
+  if (is_dir($root)) {
+    $_SERVER['DOCUMENT_ROOT'] = $root;
+  }
+  else {
+    $args[] = $root;
+  }
+
   // Rebuild imagecache presets.
   foreach (imagecache_presets(TRUE) as $preset) {
     $preset_names[] = $preset['presetname'];
@@ -130,9 +139,9 @@ function imagecache_drush_preset_build() {
   $file_query = db_query("SELECT filepath FROM {files} where filemime LIKE 'image%' ORDER BY fid DESC");
   $files = array();
   drush_log(dt('Generating file list...', array()), 'ok');
-  while ($filepath = db_result($file_query)) {
-    if (file_exists($filepath)) {
-      $files[] = $filepath;
+  while ($filepath = db_fetch_object($file_query)) {
+    if (file_exists($filepath->filepath)) {
+      $files[] = $filepath->filepath;
     }
   }
   if (empty($files)) {
