title: get-childitem get subdir name append on script directory path
body: <p>I am trying to write a PS script to find empty dirs in a directory specified by the parameter. The "empty dirs" should not contain any files and subdirs. </p>
  
  <p>This is the script:</p>
  
  <pre><code>    param (
  [parameter (mandatory=$true,position=0)]
  [string]$Path
  )
  $dirInfo = get-childitem $Path -recurse | ? {$_.PSIsContainer -eq $True} | % {get-childitem $_} | Measure-Object 
  $dirInfo | ? {$dirInfo.count -eq 0} |  Select-Object Fullname
  </code></pre>
  
  <p>When I run it on "C:\documents folder" I got the following error: </p>
  
  <pre><code>**get-childitem : Cannot find path 'C:\Documents\ManualScripts\accounts' because it does not exist.
  At C:\Documents\ManualScripts\Check-no-file-and-subdir-dir.ps1:5 char:79
  + $dirInfo = get-childitem $Path -recurse | ? {$_.PSIsContainer -eq $True} | % {ge ...
  +                                                                               ~~
      + CategoryInfo          : ObjectNotFound: (C:\Documents\ManualScripts\accounts:String) [Get-ChildItem], ItemNotFoundException
      + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand**
  </code></pre>
  
  <p>And a lot of this similar errors for each of the subfolders under C:\documents. It append the dir where the script itself is located (C:\Documents\ManualScripts) to the subdir name. </p>
  
  <p>Have done my research and still can not figure out. Any input appreciated. Thanks:)</p>
  
  <p>After the above post, I made some changes on the script but is still not work so far: </p>
  
  <pre><code>param (
  [parameter (mandatory=$true,position=0)]
  [string]$Path
  )
  
  $Dirs = Get-ChildItem $Path -recurse | ? {$_.PSIsContainer -eq $True} | ForEach-Object -Process {$_.FullName}  #get list of all directories with whole path
  
  foreach ($Dir in $Dirs) {
  $emptyDir = Get-ChildItem $Dir | Measure | where {$_.Count -eq 0} | select-Object
  }
  </code></pre>
  
  <p>Before going to bed, I believe I makes a little progress. And the script looks like this right now:</p>
  
  <pre><code>param (
  [parameter (mandatory=$true,position=0)]
  [string]$Path
  )
  $Dirs = Get-ChildItem $Path -recurse | ? {$_.PSIsContainer -eq $True} | ForEach-Object -Process {$_.FullName}  #get list of all directories with whole path
  #$Dirs | ForEach-Object {Get-ChildItem $_} | ForEach-Object {measure} | where {$_.Count -eq 0} | Select-Object $Dirs 
  ForEach ($Dir in $Dirs) {
  $emptyDir = Get-ChildItem $Dir | Measure | where {$_.Count -eq 0} | Select-Object
  $emptyDir
  }
  </code></pre>
  
  <p>If I run the there is something in output (Although is not what I expect)</p>
  
  <pre><code>PS C:\Documents\ManualScripts&gt; .\Check-no-file-and-subdir-dir-rev01.ps1
  cmdlet Check-no-file-and-subdir-dir-rev01.ps1 at command pipeline position 1
  Supply values for the following parameters:
  Path: C:\documents
  
  
  Count    : 0
  Average  : 
  Sum      : 
  Maximum  : 
  Minimum  : 
  Property : 
  
  Count    : 0
  Average  : 
  Sum      : 
  Maximum  : 
  Minimum  : 
  Property : 
  ......
  ......
  </code></pre>
  
  <p>Something like "Select-Object" picks the output of "measure" not the names of the dirs whose have no files/subdirs underneath. </p>