title: How to not have test-path search through whole directory or work around
body: <p>I have some pdf files that come zipped and I need to unzip them, and then save just first page. I have the unzip and the saving first page code working as it should. However, when I do the unzip, there are around 150 folders created out of 4000 that contain pdf and other format files inside like .txt, .csv, etc.  So my problem is I need to pull the pdf files out and move them to the main folder with the rest of the other pdfs so I can batch save the first page of each pdf.</p>
  
  <p>Folder structure after unzip would be:</p>
  
  <pre><code>SecondStorage (main folder where all pdf end after unzip)
     -Folder containing pdf and another file
     -folder containing pdf and another file
     -pdf
     -pdf
  </code></pre>
  
  <p>The PDF are always one folder level past where the rest of the pdf are located.</p>
  
  <p>I am trying to write a foreach loop that uses a test-path to see if the pdf already exists in the main folder and if it does not, then move it to the parent folder.  I keep having issues with test path telling me the pdf exists in the folder and therefore doesn't move the file.</p>
  
  <p>Here is my code I am currently using</p>
  
  <pre><code>$ListFiles = get-childitem -path $SecondStorage -Recurse -Filter "*.pdf"
  $ShortList = $ListFiles | Where-Object -Property Name -Like "20*.pdf"
  
  
  foreach ($i in $ShortList)
      {
          if (Test-Path -Path "$SecondStorage\$($i.name)" )
          {
              Move-Item -Path $i.fullname -Destination $SecondStorage
          }
          else 
          {
              Write-Output "File already exists"
          }
      }
  </code></pre>
  
  <p>When code runs, it tells me the file already exists.  I was thinking I could use literalpath but I am missing something as I keep getting the same result. </p>
  
  <p>Thanks for any suggestions you have, they are much appreciated.</p>