title: Check if a path is a folder or a file in PowerShell
body: <p>I'm trying to write a PowerShell script which goes through a list of values which are folder or file paths, and delete the files first, then remove the empty folders.</p>
  
  <p>My script so far:</p>
  
  <pre><code>[xml]$XmlDocument = Get-Content -Path h:\List_Files.resp.xml
  $Files =  XmlDocument.OUTPUT.databrowse_BrowseResponse.browseResult.dataResultSet.Path
  </code></pre>
  
  <p>Now I'm trying to test each line in the variable to see if it's a file and delete it first, and then go through and remove subfolders and folders. This is just so that it's a clean process.</p>
  
  <p>I can't quite get this next bit to work, but I think I need something like:</p>
  
  <pre><code>foreach ($file in $Files)
  {
      if (! $_.PSIsContainer)
      {
          Remove-Item $_.FullName}
      }
  }
  </code></pre>
  
  <p>The next section can clean up the subfolders and folders.</p>
  
  <p>Any suggestions?</p>