Skip to main content
Version: v3

RemoveFolderEx Element (Util Extension)

Description
Remove a folder and all contained files and folders if the parent component is selected for installation or removal. The folder must be specified in the Property attribute as the name of a property that will have a value that resolves to the full path of the folder before the CostInitialize action. Note that Directory ids cannot be used. For more details, see the Remarks.
Windows Installer references
RemoveFile Table
Parents
Component
Inner Text
None
Children
None
Attributes
NameTypeDescriptionRequired
IdStringPrimary key used to identify this particular entry. If this is not specified, a stable identifier will be generated at compile time based on the other attributes. 
OnEnumeration This value determines when the folder may be removed. This attribute's value must be one of the following:
install
Removes the folder only when the parent component is being installed (msiInstallStateLocal or msiInstallStateSource).
uninstall
Default: Removes the folder only when the parent component is being removed (msiInstallStateAbsent).
both
Removes the folder when the parent component is being installed or removed.
 
PropertyString The id of a property that resolves to the full path of the source directory. The property does not have to exist in the installer database at creation time; it could be created at installation time by a custom action, on the command line, etc. The property value can contain environment variables surrounded by percent signs such as from a REG_EXPAND_SZ registry value; environment variables will be expanded before being evaluated for a full path.  
Remarks

The custom action that implements RemoveFolderEx does so by writing temporary rows to the RemoveFile table for each subfolder of the root folder you specify. Because it might dramatically affect Windows Installer's File Costing, the temporary rows must be written before the CostInitialize standard action. Unfortunately, MSI doesn't create properties for the Directory hierarchy in your package until later, in the CostFinalize action.

An easy workaround for a typical use case of removing a folder during uninstall is to write the directory path to the registry and to load it during uninstall. See The WiX toolset's "Remember Property" pattern for an example.

If you use custom actions to set properties, ensure that they are scheduled before the WixRemoveFoldersEx custom action.

See Also
Util Schema