title: Draw Comparison between List Obtained from XML File and List Obtained from SubFolders and Modifying XML File Accordingly
body: <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;MainClass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
    &lt;Items&gt;
      &lt;Settings xsi:type="FileModel"&gt;
        &lt;Name&gt;FileOne&lt;/Name&gt;
        &lt;IsActive&gt;true&lt;/IsActive&gt;
        &lt;IsHidden&gt;false&lt;/IsHidden&gt;
      &lt;/Settings&gt;
      &lt;Settings xsi:type="FileModel"&gt;
        &lt;Name&gt;FileTwo&lt;/Name&gt;
        &lt;IsActive&gt;true&lt;/IsActive&gt;
        &lt;IsHidden&gt;false&lt;/IsHidden&gt;
      &lt;/Settings&gt; 
     &lt;Settings xsi:type="ServerModel"&gt;
        &lt;Name&gt;DelRep&lt;/Name&gt;
        &lt;IsActive&gt;false&lt;/IsActive&gt;
        &lt;IsHidden&gt;false&lt;/IsHidden&gt;
      &lt;/Settings&gt;
    &lt;/Items&gt;
    &lt;DirectoryPath&gt;D:\MainFolder&lt;/DirectoryPath&gt;
  &lt;/MainClass&gt;
  </code></pre>
  
  <p>I have the above XML File . I am trying to draw a comparison between the names of the set of sub-folders present within "D:\MainFolder" and the  Element in the above XML. If a Certain Folder is Not Present in the Location D:\MainFolder I want to Remove the entire Settings Element of that Given Name.</p>
  
  <p>For Example if there is No Sub folder Named FileOne ,  I want this Entire Junk of XML Code </p>
  
  <pre><code>&lt;Settings xsi:type="FileModel"&gt;
    &lt;Name&gt;FileOne&lt;/Name&gt;
    &lt;IsActive&gt;true&lt;/IsActive&gt;
    &lt;IsHidden&gt;false&lt;/IsHidden&gt;
  &lt;/Settings&gt;
  </code></pre>
  
  <p>To be Removed </p>
  
  <p><strong>Right Now I have the Names in the XML Stored as</strong> </p>
  
  <pre><code>List&lt;string&gt; namesInXML = settingsFile.Descendants("Items").Elements("Settings ").Where(x =&gt; x.Attribute(nameSpace + "type").Value == "FileModel").Select(x =&gt; x.Element("Name").Value).ToList();
  </code></pre>
  
  <p><strong>and the Subfolders in the D:\MainFolder</strong></p>
  
  <p><strong>Obtained from : -</strong></p>
  
  <pre><code>IEnumerable&lt;string&gt; fileNames = new DirectoryInfo(Path).EnumerateFiles("fileServer.config", SearchOption.AllDirectories).Select(fi =&gt; fi.DirectoryName).Select(dirPath =&gt; dirPath.Substring(Path.Length));
  </code></pre>
  
  <p><strong>Saved in this List</strong> </p>
  
  <pre><code>List&lt;string&gt; subFolderNames = fileNames.ToList();
  </code></pre>
  
  <p>How can I use these two List two fulfill my Requirement ?</p>