title: How to copy selected folders, subfolders and files from openFileDialog in c#
body: <p>I have a function that is suposed to copy all folders, subfolders files selected from openFileDialog from a location to another:</p>
  
  <p>I've made this function to copy all the selected paths: </p>
  
  <pre><code> public void CopiarFicheiros(string CopyTo, List&lt;string&gt; FilesToCopy )
          {
  
              foreach (var item in FilesToCopy)
              {
                  string DirectoryName = Path.GetDirectoryName(item);
                  string Copy = Path.Combine(CopyTo, DirectoryName);
                  if (Directory.Exists(Copy) &amp;&amp; DirectoryName.ToLower() != "newclient" &amp;&amp; DirectoryName.ToLower() != "newservice")
                  {
                      Directory.CreateDirectory(Copy);
                      File.Copy(item, Copy + @"\" + Path.GetFileName(item), true);
                  }
                  else File.Copy(item, CopyTo + @"\" + Path.GetFileName(item), true);
              }
  
          }
  </code></pre>
  
  <p>The logic is full of flaws and I'm running out of time and can't seem to find a proper solution to this.</p>
  
  <p>This is how I get the selected files and folders from the dialog:</p>
  
  <pre><code>  private List&lt;string&gt; GetFiles()
          {
              var Files = new List&lt;string&gt;();
              if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
              {
                  string sFileName = openFileDialog.FileName;
                  string[] arrAllFiles = openFileDialog.FileNames;
                  Files = arrAllFiles.ToList();
              }
              return Files;
          }
  </code></pre>
  
  <p>Does anyone have a better solution or a clue to what I need to change to successfully do this?
  Any help is highly appreciated, thank you </p>