$cs.File_DelEmptyFolder
Description
Section titled “Description”Deletes the folder at path, but only if it is completely empty. “Empty” is determined by summing the size of every file anywhere under the folder, recursively — so a folder that only contains empty subfolders is still deleted. If path doesn’t exist, or if it isn’t empty, the function does nothing and does not raise an error.
Syntax
Section titled “Syntax”$cs.File_DelEmptyFolder(string path)
Parameters
Section titled “Parameters”path (String)
Section titled “path (String)”Folder to delete if it is empty.
Return value
Section titled “Return value”None.
Example
Section titled “Example”$cs.File_DelEmptyFolder("$env:ProgramData\Notepad++")In PostUninstall, after removing the application’s files, use it to tidy up the install folder only if nothing else was left behind in it:
$InstallFolder = "C:\Program Files\Contoso\App"$cs.File_DelFile((Join-Path $InstallFolder "app.exe"))$cs.File_DelEmptyFolder($InstallFolder)It’s also safe to call on a folder that only contains empty subfolders, since emptiness is checked recursively by total file size:
$cs.File_DelEmptyFolder("$env:ProgramData\Contoso\App\Cache")