title: Check same name files in folder with different extensions, if exists, move one out
body: <p>Every morning, a folder gets the same named zip files transferred to it. I currently have script that will check for non-zipped files, and if they exist, an archive folder is created, and they are moved there. Then the zip files are unzipped and the then the zip file is deleted.</p>
  
  <p>A new condition came in, that 1 file will not have a daily transfer, but it will be weekly (random day of the week), and that the associated non-zipped file must remain in the folder until that zip file is transferred in.</p>
  
  <p>How would I rework my code to check the zipped file names against the non-zipped, and if there is a match, to move only those files before unzipping the rest?</p>
  
  <p>My current code:
  First <code>if</code> statement tests for non-existing zip files. If exists, a new archive directory is created with the date. Then those non-zips are moved to this folder.</p>
  
  <p>Second <code>if</code> statement checks for zip files, if exists, it will unzip each one, then delete the zip files.</p>
  
  <pre><code>$dir = "D:\test"
  $date = Get-Date -Format "yyyy-MMM-dd"
  
  if (Test-Path "$dir\*" -Exclude *.zip -PathType Leaf) {
      $newDir = New-Item -Type Directory -Path "$dir\Archive\$date" -Force
      $nozip = gci -Recurse $dir -Exclude *.zip | where { ! $_.PSIsContainer }
  
      foreach ($file in $nozip) {
          Move-Item $file $newDir
      }
  }
  if (Test-Path "$dir\*.zip" -PathType Leaf) {
      $list = gci -Recurse $dir -Include *.zip
      $shell = New-Object -COM Shell.Application
  
      foreach ($file in $list) {
          $zip = $shell.NameSpace($file.FullName)
          foreach ($item in $zip.Items()) {
              $shell.NameSpace($dir).CopyHere($item)
          }
          Remove-Item $file
      }
  } else {
      exit
  }
  </code></pre>
  
  <p>Sample scenario: </p>
  
  <p>Folder D:\Test contains files A.txt, B.txt and C.txt.<br>
  Every morning files B.zip and C.zip, containing a new B.txt and C.txt, are transferred to the same folder, D:\Test. </p>
  
  <p>The zip files need to be unzipped, but the corresponding B.txt and C.txt that are already in this folder, need to be moved out to D:\Test\Archive, then B.zip and C.zip can be unzipped, leaving a new B.txt and C.txt in D:\Test, and then those zip files are deleted.  </p>
  
  <p>The piece I am having issues with, is that A.zip is not transferred daily.  It's once a week and until that A.zip hits the folder, A.txt needs to stay in D:\Test.   </p>
  
  <p>Right now, my script moves all non zip files to D:\Test\Archive every day.  So when B.zip and C.zip come into D:\Test, there will be no A.txt after the process is done, it is being moved to D:\Test\Archive with the rest of the files. </p>
  
  <p>So I need a way to check all the .txt files against the .zip files, and if there is a match by file name, not the extension, then move that non zipped file to D:\Test\Archive.  If there is no match, leave that non zipped file in D:\Test and continue processing those that do match. </p>