# $cs.File_GetFolderSize

> Calculates the total size, in bytes, of every file under path, including all subfolders. Throws DirectoryNotFoundException if path doesn't exist.

Source: https://docs.capaone.com/capainstaller/powerpacks/cs-file-getfoldersize/  
Product: CapaInstaller — a separate CapaSystems product; do not apply this page to any other.

### Description

Calculates the total size, in bytes, of every file under `path`, including all subfolders. Throws `DirectoryNotFoundException` if `path` doesn't exist.

### Syntax

$cs.File_GetFolderSize(string path)

### Parameters

#### path (String)

Full path of the folder to measure.

### Return value

Long, the total size of the folder contents in bytes.

### Example

**PowerShell**

```powershell
$logFolder = $global:AppLogFolder
if ($cs.File_ExistDir($logFolder))
{
  $sizeInBytes = $cs.File_GetFolderSize($logFolder)
  $cs.Job_WriteLog("Log folder size: $sizeInBytes bytes")
}
```

Sanity-check that an extraction step actually produced files, rather than silently leaving an empty folder:

```powershell
$extractFolder = Join-Path $global:Packageroot "Extracted"
if ($cs.File_ExistDir($extractFolder))
{
  $sizeInBytes = $cs.File_GetFolderSize($extractFolder)
  if ($sizeInBytes -eq 0)
  {
    Exit-PSScript -exitcode 1 -exitmessage "Extraction produced an empty folder, aborting install"
  }
}
```

Log how much space a data folder is using before removing it during cleanup:

```powershell
$dataFolder = Join-Path $env:ProgramData "Contoso\Cache"
if ($cs.File_ExistDir($dataFolder))
{
  $sizeInMb = [math]::Round($cs.File_GetFolderSize($dataFolder) / 1MB, 2)
  $cs.Job_WriteLog("Removing cache folder ($sizeInMb MB) at $dataFolder")
  $cs.File_DelTree($dataFolder)
}
```

### Related functions

[$cs.File_ExistDir](/capainstaller/powerpacks/cs-file-existdir/) [$cs.File_DelTree](/capainstaller/powerpacks/cs-file-deltree/)
