title: Powershell, GCI bugging out? Non-empty Folder size returns 0
body: <p>I wrote a powershell script that calculates the size of subfolders in a parent dir by recursively adding the filesizes of each file inside found using <code>gci</code> function.</p>
  <p>This works for most folders, except this folder:
  <code>&quot;\Fall Out Boy - A Little Less Sixteen Candles, A Little More [Touch Me]&quot;</code></p>
  <p>Variable <code>$curfoldersize</code> should be giving a value of <code>23089406</code> (22mb), but the function <code>Get-FolderSize</code> returns 0 instead. For some reason the code only breaks on this folder, other folder names seem to work fine. I'm not sure what's causing the bug here.</p>
  <p>Folder contents:
  <a href="https://i.stack.imgur.com/52rQ8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/52rQ8.png" alt="enter image description here" /></a></p>
  <pre><code># Parent Directory to find folders
  $dirpath = &quot;H:\Parent Dir\&quot;
  $logpath = &quot;$PSScriptRoot\Logs\&quot;
  $logpath = -join($logpath, ($dirpath|split-path -leaf), &quot;.txt&quot;)
  
  # Maximum size of each folder (empty or non-empty)
  $foldermaxsize = 19 # &lt;- max size of each folder (e.g. 10 * 1MB = 10MB, 10 * 1KB = 10KB, etc)
  $sizeunit = 1MB # &lt;- size denominator (e.g. 1KB, 1MB, 1GB, etc)
  
  $foldermaxsize = $foldermaxsize * $sizeunit
  
  
  # returns size of single folder by summing all items (recursive) inside
  Function Get-FolderSize {
      # allows cmd options 
      [cmdletbinding()]
      Param ( 
          [Parameter(Mandatory=$true, Position=0, ValueFromPipeline = $true)]
          $folderpath
      )
      $size = 0
      # calculate folder size and recurse as needed
      Foreach ($file in $(gci $folderpath -recurse -Force)){
       If (-not ($file.psiscontainer)) {
          $size += $file.length
          }
      }
  
      # return the value and go back to caller
      return $size
  }
  
  
  # Array containing filepaths of each directory (recursive) found within $dirpath
  # gci = GetChildItem
  $Folders = @(gci $dirpath -Recurse | ?{ $_.PSIsContainer } |  Select-Object -ExpandProperty FullName) 
  
  # Check for null results from cgi function
  if ($Folders.length -eq 0) {
    write-host &quot;   no folders.&quot; 
  } else {
      # $folder = full path of current folder
      ForEach ($folder in $Folders){
          # returns int size of Folder (by recursively summing all child filesize)
          $curfoldersize = Get-FolderSize $folder 
          Write-Output $curfoldersize
      }
  
  
  
  if ($Host.Name -eq &quot;ConsoleHost&quot;)
  {
      Write-Host &quot;Press any key to continue...&quot;
      $Host.UI.RawUI.ReadKey(&quot;NoEcho,IncludeKeyUp&quot;) &gt; $null
  }
  
  }
  </code></pre>