--- includes/barcode.admin.inc	2009-11-30 23:25:25.000000000 +0100
+++ includes/barcode.admin.inc.2	2009-12-05 01:37:46.892503954 +0100
@@ -88,5 +88,42 @@ function barcode_settings() {
     '#required' => TRUE,
   );
 
+  $form['barcode_clear_images'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Flush generated barcodes'),
+    '#description' => t('Flushing all generated barcodes will result in the generation of new barcode images using the new settings. This process may however result in high server loads on sites with a lot of traffic.'),
+  );
+
+  $form['#submit'] = array('barcode_settings_submit');
+
   return system_settings_form($form);
 }
+
+function barcode_settings_submit($form, &$form_state) {
+  if($form['barcode_clear_images']['#value']) {
+    // User checked the 'Clear generated barcodes' checkbox.
+    $barcode['file_path'] = file_directory_path() . '/' . variable_get('barcode_default_path', 'barcodes'); 
+
+    if(!file_check_directory($barcode['file_path'])) {
+      // Path does not exist
+      drupal_set_message(t('Path not found. No images have been deleted.'), 'warning');
+    }
+    else {
+      $barcode_delete_counter = 0;
+      foreach(file_scan_directory($barcode['file_path'], '.*\.'.variable_get('barcode_image_format', 'png')) as $barcode_file) {
+        // Try to remove the image file.
+        if(file_delete($barcode_file->filename)) {
+          $barcode_delete_counter++;
+	}
+        else {
+          drupal_set_message(t("Could not remove '@filename'. File not found.", array('@filename' => $barcode_file->basename)), 'warning');
+        }
+      }
+      drupal_set_message(t('!amount barcode !images been deleted.', array(
+        '!amount' => $barcode_delete_counter,
+        '!images' => format_plural($barcode_delete_counter, 'image has', 'images have'))));
+    }
+  }
+  // No need to store the checkbox value in the database.
+  unset($form_state['values']['barcode_clear_images']);
+}
