title: Powershell script to copy files to folders by matching file to folder names
body: <p>I have a directory with empty folders, let's call it D1. And another directory (let's call it D2) with files which are named such that the file name contains the folder names from D1. I want to match the file names from D2 to folder names from D1 and copy (not move) the files to the corresponding folder in D1. Can this be done using Powershell? As an example,
  D1 looks like:</p>
  <pre><code>FolderName1
  FolderName2
  FolderName3
  </code></pre>
  <p>And files in D2 look like:</p>
  <pre><code>abcd.FolderName1.txt
  xyz.FolderName2.txt
  qwerty.FolderName3.txt
  </code></pre>
  <p>EDIT: the folder names above are just an example. The actual folder/file names could vary e.g. to <code>Folder#Name</code>, <code>My_Folder</code>, <code>abcd.1234.Folder_Name</code> etc.</p>