diff --git a/cck.install b/cck.install
index 49a2f9b..dab211a 100644
--- a/cck.install
+++ b/cck.install
@@ -93,3 +93,91 @@ function cck_update_7000() {
     db_add_field('cck_field_settings', 'language', $field);
   }
 }
+
+function cck_update_7001(&$sandbox = array()) {
+  $ret = array();
+
+  // Query the existing D6 files table for possible duplicate URIs in D7.
+  if (db_table_exists('files')) {
+
+    if (!isset($sandbox['progress'])) {
+      $sandbox['progress'] = 0;
+      $sandbox['current_file'] = '';
+      $sandbox['max'] = db_query("SELECT COUNT(f1.fid) FROM {files} f1 WHERE (SELECT count(f2.filepath) FROM {files} f2 WHERE f2.filepath = f1.filepath) > 1 ORDER BY f1.filename")->fetchField();
+    }
+
+    // Update 50 files at a time.
+    $query = "SELECT f1.fid, f1.filename, f1.filepath FROM {files} f1 WHERE (SELECT count(f2.filepath) FROM {files} f2 WHERE f2.filepath = f1.filepath) > 1 ORDER BY f1.filename";
+    $result = db_query_range($query, $sandbox['current_file'], 5);
+    $last_file = '';
+    $current_file = '';
+    $batch_size = 5;
+
+/*
+    // SELECT count(f2.filepath) FROM {files} f2 WHERE f2.filepath = f1.filepath
+    $sub_query = db_select('files', 'f2');
+    $sub_query->addExpression('COUNT(f2.filepath)');
+    $sub_query->condition('f2.filepath', 'f1.filepath', '=');
+    $sub_query->execute()->fetchField();
+
+    // SELECT f1.fid, f1.filename, f1.filepath FROM {files} f1 WHERE (sub_query) > 1 ORDER BY f1.filename
+    $query = db_select('files', 'f1');
+    $query->addField('f1', 'fid');
+    $query->addField('f1', 'filename');
+    $query->addField('f1', 'filepath');
+    $query->condition($sub_query, '1', '>');
+    $query->range(0, $batch_size);
+    $query->orderBy('f1.filename', 'ASC');
+    $result = $query->execute();
+*/
+
+    foreach ($result as $record) {
+      $current_file = strtolower($record->filepath);
+
+      if ($current_file == $last_file) {
+        // Log an error if the file copy destination is not writable.
+        $directory = str_replace('/' . $old_file, '', $record->filepath);
+        if (!file_prepare_directory($directory, FILE_CREATE_DIRECTORY)) {
+          watchdog('cck', 'The directory %directory could not be created or is not accessible.', array('%directory' => $directory));
+        }
+        else {
+          // Log an error if the destination does not contain a valid stream.
+          $destination = variable_get('file_default_scheme', 'public') . '://';
+          $destination_scheme = file_uri_scheme($destination);
+          if (!$destination_scheme || !file_stream_wrapper_valid_scheme($destination_scheme)) {
+            watchdog('cck', 'The file could not be copied, because the destination %destination is invalid.', array('%destination' => $destination), 'error');
+          }
+          else {
+            $files_dir = variable_get('file_directory_path', 'files') . '/';
+            $path_without_files = strtolower(str_replace($files_dir, '', $record->filepath));
+            // Get the new file location and copy the file.
+            $new_uri = file_destination($destination . $path_without_files, FILE_EXISTS_RENAME);
+            $new_filename = array_pop(explode('/', $new_uri));
+            $new_filepath = $files_dir . str_replace($destination, '', $new_uri);
+            // Copy the file on disk.  Leaving the original file in place means embeded links will still work.
+            if (!copy($record->filepath, $new_filepath)) { 
+              watchdog('cck', t('Unable to safely copy file from !old to !new', array('!old' => $record->filepath, '!new' => $new_filepath)), 'error');
+            }
+            // Update the database to use the new filename.
+            $num_updated = db_update('files') 
+              ->fields(array(
+                'filename' => $new_filename,
+                'filepath' => $new_filepath,
+              ))
+              ->condition('fid', $record->fid, '=')
+              ->execute();
+            drupal_set_message('Updated file: ' . $record->fid);
+          }
+        }
+      }
+      $last_file = strtolower($record->filepath);
+
+      $sandbox['progress']++;
+      $sandbox['current_file'] = $current_file;
+    }
+
+    $ret['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
+  }
+
+  return $ret;
+}
