<p>I would like to modify an MSI installer (created through <a href="http://en.wikipedia.org/wiki/WiX" rel="noreferrer">WiX</a>) to delete an entire directory on uninstall.</p>

<p>I understand the <code>RemoveFile</code> and <code>RemoveFolder</code> options in WiX, but these are not robust enough to recursively delete an entire folder that has content created after the installation.</p>

<p>I noticed the similar Stack Overflow question <em><a href="https://stackoverflow.com/questions/195919">Removing files when uninstalling WiX</a></em>, but I was wondering if this could be done more simply using a call to a batch script to delete the folder.</p>

<p>This is my first time using WiX, and I'm still getting the hang of <a href="http://wix.sourceforge.net/manual-wix2/authoring_custom_actions.htm" rel="noreferrer">custom actions</a>. What would be a basic example of a custom action that will run a batch script on uninstall?</p>

You can do this with a custom action.  You can add a refrence to your custom action under
```
<InstallExecuteSequence>
```
:
```
```
<InstallExecuteSequence>
...
  <Custom Action="FileCleaner" After='InstallFinalize'>
          Installed AND NOT UPGRADINGPRODUCTCODE</Custom>
```
```
Then you will also have to define your Action under
```
<Product>
```
:
```
```
<Product> 
...
  <CustomAction Id='FileCleaner' BinaryKey='FileCleanerEXE' 
                ExeCommand='' Return='asyncNoWait'  />
```
```
Where FileCleanerEXE is a binary (in my case a little c++ program that does the custom action) which is also defined under
```
<Product>
```
:
```
```
<Product> 
...
  <Binary Id="FileCleanerEXE" SourceFile="path\to\fileCleaner.exe" />
```
```
The real trick to this is the
```
Installed AND NOT UPGRADINGPRODUCTCODE
```
condition on the Custom Action, with out that your action will get run on every upgrade (since an upgrade is really an uninstall then reinstall). Which if you are deleting files is probably not want you want during upgrading.
On a side note: I recommend going through the trouble of using something like C++ program to do the action, instead of a batch script because of the power and control it provides -- and you can prevent the "cmd prompt" window from flashing while your installer runs.