title: How can I list every resource files of a directory pack URI?
body: <p>I have many XML files with "Build Action" set as "Resource". I can access them from code using the well known pack URI scheme, or just a relative URI (which is actually a valid pack URI, as stated by Microsoft in the pack URI msdn page, so everything is a pack uri :p), like this :</p>
  
  <pre><code>Uri uri1 = new Uri("pack://application:,,,/someFolder/myResource1.xml");
  Uri uri2 = new Uri("someFolder/myResource2.xml");
  </code></pre>
  
  <p>Actually, I need to get a stream from each xml file. What I can do is the following :</p>
  
  <pre><code>Uri uri1 = new Uri("pack://application:,,,/someFolder/myResource1.xml");
  var stream1 = App.GetResourceStream(uri1).Stream; // works fine
  </code></pre>
  
  <p>It works fine and I get my streams. Now here are my questions :  </p>
  
  <p><strong>What if I do not know the names of my resources ?</strong> (only the path to "someFolder")<br>
  <strong>How can I list them ?</strong>  </p>
  
  <p>I cannot use Directory.GetFiles since resources are embedded into the assembly. A possible solution is to set the build action of my resources as "Embedded Resources" and then use the <code>assembly.GetManifestResourceNames()</code> function, but I'm stubborn and do not want to change this build action :p</p>
  
  <p>Thanks !  </p>
  
  <p>EDIT : I came to something like this :</p>
  
  <pre><code>    /// &lt;summary&gt;
      /// Returns a dictionary of the assembly resources (not embedded).
      /// &lt;/summary&gt;
      /// &lt;param name="filter"&gt;A regex filter for the resource paths.&lt;/param&gt;
      public static IDictionary&lt;string, object&gt; GetResources(string filter) {
          var asm = Assembly.GetEntryAssembly();
          string resName = asm.GetName().Name + ".g.resources";
          Stream stream = asm.GetManifestResourceStream(resName);
          ResourceReader reader = new ResourceReader(stream);
  
          IDictionary&lt;string, object&gt; ret = new Dictionary&lt;string, object&gt;();
          foreach (DictionaryEntry res in reader) {
              string path = (string)res.Key;
              if (Regex.IsMatch(path, filter))
                  ret.Add(path, res.Value);
          }
          return ret;
      }
  </code></pre>