Index: /main/trunk/greenstone2/perllib/plugins/DSpacePlugin.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/DSpacePlugin.pm	(revision 24970)
+++ /main/trunk/greenstone2/perllib/plugins/DSpacePlugin.pm	(revision 24971)
@@ -50,4 +50,5 @@
 use ReadTextFile;
 use plugin;
+use util;
 use XMLParser;
 use strict;
@@ -249,4 +250,10 @@
     my @fname_list = map { "(".$_->{'file'}.")" } @$fnamemime_list;
     my $fname_re = join("|",@fname_list);
+	
+	# Indexing into the extrameta data structures requires the filename's style of slashes to be in URL format
+	# Then need to convert the filename to a regex, no longer to protect windows directory chars \, but for
+	# protecting special characters like brackets in the filepath such as "C:\Program Files (x86)\Greenstone".
+	$fname_re = &util::filepath_to_url_format($fname_re); # just in case there are slashes in there 
+	
     $fname_re =~ s/\./\\\./g;
 
Index: /main/trunk/greenstone2/perllib/plugins/DirectoryPlugin.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/DirectoryPlugin.pm	(revision 24970)
+++ /main/trunk/greenstone2/perllib/plugins/DirectoryPlugin.pm	(revision 24971)
@@ -482,11 +482,9 @@
     # filter out any extrametakeys that mention subdirectories and store
     # for later use (i.e. when that sub-directory is being processed)
-    foreach my $ek (@extrametakeys) {
-	my ($subdir_re,$extrakey_dir) = &File::Basename::fileparse($ek);
-	$extrakey_dir = &util::unregex_filename($extrakey_dir);
-
-	my $dirsep_re = &util::get_re_dirsep();
-
-	my $ek_non_re = &util::unregex_filename($ek);
+    foreach my $ek (@extrametakeys) { # where each Extrametakey (which is a filename) is stored as a regex
+	my $ek_non_re = &util::unregex_filename($ek); # unregex it. This step is *also* required for the fileparse operation since the file suffix
+												  # will be specified as \.txt and we don't want fileparse to split it there making \.txt the "filename"
+	my ($subdir_re,$extrakey_dir) = &File::Basename::fileparse($ek_non_re);		
+	my $dirsep_re = &util::get_re_dirsep();	
 	if ($ek_non_re =~ m/$dirsep_re/) { # specifies at least one directory
 	    my $md = &extrametautil::getmetadata(\%extrametadata, $ek);
@@ -494,4 +492,10 @@
 
 	    my $subdir_extrametakeys = $self->{'subdir_extrametakeys'};
+		
+	# Indexing into the extrameta data structures requires the filename's style of slashes to be in URL format
+	# Then need to convert the filename to a regex, no longer to protect windows directory chars \, but for
+	# protecting special characters like brackets in the filepath such as "C:\Program Files (x86)\Greenstone".
+	$subdir_re = &util::filepath_to_url_format($subdir_re); # Possibly not necessary since subdir_re is the last segment of the filepath $ek #### 
+	$subdir_re = &util::filename_to_regex($subdir_re);      # Escape any special chars like brackets and . in subdir_re
 		
 	    my $subdir_rec = { 're' => $subdir_re, 'md' => $md, 'mf' => $mf };
Index: /main/trunk/greenstone2/perllib/plugins/EmbeddedMetadataPlugin.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/EmbeddedMetadataPlugin.pm	(revision 24970)
+++ /main/trunk/greenstone2/perllib/plugins/EmbeddedMetadataPlugin.pm	(revision 24971)
@@ -30,4 +30,5 @@
 use BasePlugin;
 use extrametautil;
+use util;
 
 use Encode;
@@ -325,6 +326,9 @@
     }
 
-    # Protect windows directory chars \
-    $file = &util::filename_to_regex($file); #### 
+    # Indexing into the extrameta data structures requires the filename's style of slashes to be in URL format
+	# Then need to convert the filename to a regex, no longer to protect windows directory chars \, but for
+	# protecting special characters like brackets in the filepath such as "C:\Program Files (x86)\Greenstone".
+	$file = &util::filepath_to_url_format($file);
+    $file = &util::filename_to_regex($file); 
     
     # Associate the metadata now
Index: /main/trunk/greenstone2/perllib/plugins/LOMPlugin.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/LOMPlugin.pm	(revision 24970)
+++ /main/trunk/greenstone2/perllib/plugins/LOMPlugin.pm	(revision 24971)
@@ -36,4 +36,5 @@
 use MetadataPass;
 use MetadataRead;
+use util;
 use XMLParser;
 use Cwd;
@@ -166,4 +167,9 @@
 	$file_re = $tail;
     }
+	
+	# Indexing into the extrameta data structures requires the filename's style of slashes to be in URL format
+	# Then need to convert the filename to a regex, no longer to protect windows directory chars \, but for
+	# protecting special characters like brackets in the filepath such as "C:\Program Files (x86)\Greenstone".
+	$file_re = &util::filepath_to_url_format($file_re);
     $file_re = &util::filename_to_regex($file_re);
     $self->{'lom_srcdoc'} = undef; # reset for next file to be processed
Index: /main/trunk/greenstone2/perllib/plugins/MetadataCSVPlugin.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/MetadataCSVPlugin.pm	(revision 24970)
+++ /main/trunk/greenstone2/perllib/plugins/MetadataCSVPlugin.pm	(revision 24971)
@@ -36,4 +36,5 @@
 use extrametautil;
 use multiread;
+use util;
 
 use Encode;
@@ -205,4 +206,8 @@
 
  	# Associate the metadata now
+	# Indexing into the extrameta data structures requires the filename's style of slashes to be in URL format
+	# Then need to convert the filename to a regex, no longer to protect windows directory chars \, but for
+	# protecting special characters like brackets in the filepath such as "C:\Program Files (x86)\Greenstone".
+	$csv_line_filename = &util::filepath_to_url_format($csv_line_filename);
 	$csv_line_filename = &util::filename_to_regex($csv_line_filename);
 
Index: /main/trunk/greenstone2/perllib/plugins/MetadataXMLPlugin.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/MetadataXMLPlugin.pm	(revision 24970)
+++ /main/trunk/greenstone2/perllib/plugins/MetadataXMLPlugin.pm	(revision 24971)
@@ -328,4 +328,16 @@
     if ($element eq "FileSet") {
 	foreach my $target (@{$self->{'saved_targets'}}) {
+	
+		# Indexing into the extrameta data structures requires the filename's style of slashes to be in URL 
+		# format. But if metadata.xml was user-constructed, its FileName fields (stored in the saved_targets 
+		# map) could represent pathnames in Windows format using \ as file separator, instead of pathnames 
+		# being in URL format as Greenstone would've generated. Need to convert such filepaths to URL style 
+		# paths. Then need convert this to a regex to protect special characters like brackets in the 
+		# filepath, such as "C:\Program Files (x86)\Greenstone".
+		
+		$target = &util::unregex_filename($target); # filename is a regex, before converting it to URL form, unregex it
+		$target = &util::filepath_to_url_format($target); # convert to URL form
+		$target = &util::filename_to_regex($target); # regex it. Now we have regexed URL form of filename
+	
 		my $file_metadata = &extrametautil::getmetadata($self->{'metadataref'}, $target);
 	    my $saved_metadata = $self->{'saved_metadata'};
Index: /main/trunk/greenstone2/perllib/plugins/OAIPlugin.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/OAIPlugin.pm	(revision 24970)
+++ /main/trunk/greenstone2/perllib/plugins/OAIPlugin.pm	(revision 24971)
@@ -38,4 +38,5 @@
 use metadatautil;
 use MetadataRead;
+use util;
 
 # methods with identical signatures take precedence in the order given in the ISA list.
@@ -255,6 +256,12 @@
     # return all the metadata we have extracted to the caller.
     # Directory plug will pass it back in at read time, so we don't need to extract it again.
-    # extrametadata keys should be regular expressions
+    
+	# Extrametadata keys should be regular expressions
+	# Indexing into the extrameta data structures requires the filename's style of slashes to be in URL format
+	# Then need to convert the filename to a regex, no longer to protect windows directory chars \, but for
+	# protecting special characters like brackets in the filepath such as "C:\Program Files (x86)\Greenstone".
+	$filename_for_metadata = &util::filepath_to_url_format($filename_for_metadata);
     $filename_for_metadata = &util::filename_to_regex($filename_for_metadata);
+	
     &extrametautil::setmetadata($extrametadata, $filename_for_metadata, $new_metadata);
     &extrametautil::addmetakey($extrametakeys, $filename_for_metadata);
Index: /main/trunk/greenstone2/perllib/util.pm
===================================================================
--- /main/trunk/greenstone2/perllib/util.pm	(revision 24970)
+++ /main/trunk/greenstone2/perllib/util.pm	(revision 24971)
@@ -837,5 +837,5 @@
     my $filename = shift (@_);
 
-    # need to put single backslash back to double so that regex works
+    # need to make single backslashes double so that regex works
     $filename =~ s/\\/\\\\/g; # if ($ENV{'GSDLOS'} =~ /^windows$/i);    
 	
@@ -1067,14 +1067,7 @@
 	# convert parameters only to / slashes if Windows
     
-	my $filename_urlformat = $filename;
-	my $within_dir_urlformat = $within_dir;
-	
-	if ($ENV{'GSDLOS'} =~ /^windows$/i) {
-		# Only need to worry about Windows, as Unix style directories already in url-format
-		# Convert Windows style \ => /
-		$filename_urlformat =~ s@\\@/@g;
-		$within_dir_urlformat =~ s@\\@/@g;
-	}
-	
+	my $filename_urlformat = &filepath_to_url_format($filename);
+	my $within_dir_urlformat = &filepath_to_url_format($within_dir);
+
 	#if ($within_dir_urlformat !~ m/\/$/) {
 		# make sure directory ends with a slash
@@ -1092,4 +1085,17 @@
     
     return $filename_urlformat;
+}
+
+# Convert parameter to use / slashes if Windows (if on Linux leave any \ as is,
+# since on Linux it doesn't represent a file separator but an escape char).
+sub filepath_to_url_format
+{
+	my ($filepath) = @_;
+	if ($ENV{'GSDLOS'} =~ /^windows$/i) {
+		# Only need to worry about Windows, as Unix style directories already in url-format
+		# Convert Windows style \ => /
+		$filepath =~ s@\\@/@g;		
+	}
+	return $filepath;
 }
 
