# $cs.File_DelFile

> Deletes a file. By default, only the exact file at filepath is deleted, and nothing happens if it doesn't exist.

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

### Description

Deletes a file. By default, only the exact file at `filepath` is deleted, and nothing happens if it doesn't exist. If `recursive = $true`, the filename portion of `filepath` is instead treated as a search pattern (wildcards allowed, e.g. `*.tmp`) and every matching file found anywhere under `filepath`'s parent folder tree is deleted, case-insensitively.

### Syntax

$cs.File_DelFile(string filepath, bool recursive = false)

### Parameters

#### filepath (String)

File to delete. When `recursive` is `$true`, the filename part of this path is used as a wildcard search pattern instead.

#### recursive (Boolean)

If `$true`, searches the parent folder tree of `filepath` for files matching the filename pattern and deletes all matches. Default is `$false` (deletes only the exact file). Can throw an error if a matched file cannot be deleted due to permissions.

### Return value

None.

### Example

**PowerShell**

```powershell
$cs.File_DelFile("C:\Program Files\CapaInstaller\dummy.exe")
```

To delete every `*.tmp` file anywhere under a folder tree:

```powershell
$cs.File_DelFile("C:\Program Files\CapaInstaller\*.tmp", $true)
```

In `PostInstall`, remove a single leftover file the installer left behind:

```powershell
$cs.File_DelFile((Join-Path $env:TEMP "setup_bootstrapper.exe"))
```

Clean up every `*.log` file scattered under an application's data folder tree during uninstall:

```powershell
$cs.File_DelFile("C:\ProgramData\Contoso\App\*.log", $true)
```

### Related functions

[$cs.File_DelTree](/capainstaller/powerpacks/cs-file-deltree/) [$cs.File_ExistFile](/capainstaller/powerpacks/cs-file-existfile/)
