title: Rename Folders to match filename inside
body: <p>I have a bunch of folders that I need changed as follows:</p>
  
  <p><strong>before:</strong></p>
  
  <ul>
  <li>FolderNamedX (2016)
  
  <ul>
  <li>fileNamedY.png</li>
  </ul></li>
  </ul>
  
  <p><strong>after:</strong></p>
  
  <ul>
  <li><p>NamedSameAsFileWithin (2016)</p>
  
  <ul>
  <li>fileNamedY.png</li>
  </ul></li>
  </ul>
  
  <p>Essentially, folder name needs to change to match the name of the file inside it and retain the year at the same time.</p>
  
  <p>I am trying to do this using PowerShell.
  Any kind soul can steer me in the right direction?</p>
  
  <p>I am very new to PowerShell and so far I have something like this (don't laugh too hard):</p>
  
  <pre><code>Get-ChildItem -Path "C:\Lab" | ForEach-Object -Process {
      $Filename = Filename.Trim(".png") # Not sure how to retrieve the filename from current folder
      $OldFolderName = $_.Name
      $NewFolderNameLeft, $NewFolderNameRight = $OldFolderName.Split("(")
      $NewFolderNameLeft = $Filename
      Rename-item -Path $_.Name -NewName ($NewFolderNameLeft+"("+$NewFolderNameRight) -WhatIf
  }
  </code></pre>