$cs.File_DelFile
Description
Section titled “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
Section titled “Syntax”$cs.File_DelFile(string filepath, bool recursive = false)
Parameters
Section titled “Parameters”filepath (String)
Section titled “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)
Section titled “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
Section titled “Return value”None.
Example
Section titled “Example”$cs.File_DelFile("C:\Program Files\CapaInstaller\dummy.exe")To delete every *.tmp file anywhere under a folder tree:
$cs.File_DelFile("C:\Program Files\CapaInstaller\*.tmp", $true)In PostInstall, remove a single leftover file the installer left behind:
$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:
$cs.File_DelFile("C:\ProgramData\Contoso\App\*.log", $true)