Windows Installer, Java Installer, Freeware Installer
Home|Contact|Site Map|TOC|Search
Download  Features   Java  Licensing  Purchase  Testimonials  Support  Forums

How do I remove a file or a folder during installation?

Answer

The first step in removing a file or a folder is finding it's path. For this you can use a "New Search" or a "New File Search" in the Search page.

Find the path of a folder

This can be done by following these steps:

  • go to the "Search" page and create a "New Search"
  • while it is selected, press F2 and rename it to something meaningful (for example MY_FOLDER)
  • right-click the search and use the "Add Location" menu to add a Folder location
  • in the Directory Properties page configure the folder you want to find

The property used by the search ("MY_FOLDER") will contain the path to the folder (if it has been found).

Removing a folder

Under normal circumstances a folder will be uninstalled automatically. However, if it contains resources which were not created by the installation package, the folder will not be removed.

If you know the files which remain you can use File Removal Operations to remove all the files in the folder. However, if you don't know what the folder will contain, you can use a custom action:

Function removeDir()
   Dim pathToFolder, smallPath
   Set objFS = CreateObject("Scripting.FileSystemObject")
   pathToFolder = Session.Property("MY_FOLDER")   
   smallPath=Left(pathToFolder,Len(pathToFolder)-1)     
   If (objFS.FolderExists(smallPath)) then
      objFS.DeleteFolder smallPath, true     
   End if
End Function

This code can be pasted into a .VBS file which can be added as an Attached custom action. You can execute this custom action whenever you want by scheduling it under a standard action ("InstallFinalize" for example).

ImportantThe Function Name of the above custom action must be set to removeDir in order to run the script. Also, this custom action must be set as Immediate.

Find the folder which contains a file

In order to find the path of the folder which contains your file, you first need to find the file. This can be done by following these steps:

  • go to the "Search" page and create a "New File Search"
  • rename it to something meaningful (for example MY_FILE)
  • configure the File to Search page to search for your file
  • right-click the search and use the "Add Location" menu to add a Folder location in which to search the file

The property used by the search ("MY_FILE") will contain the path to the file (if it has been found). In order to obtain the path of the folder which contains this file, you can use a custom action:

Dim path
path=Session.property("MY_FILE")
smallPath=Left(path,InStrRev(path,"\")-1)
smallPath=Left(path,InStrRev(smallpath,"\"))
Session.property("MY_FILE")=smallPath
      

NoteThe custom actions which affect the result of a search can be scheduled under the "InstallExecuteSequence" -> "AppSearch" standard action. You can see this standard action by using the "Show Standard Action" button on the toolbar in the "Custom Actions" page.

ImportantThe Function Name of the above custom action must be empty in order to run the script.

Remove a file

Once you have the path of the folder which contains your file you have two options for removing it:

  • you use a File Removal operation to remove the file
  • you use the custom action which removes the entire folder

If you use a file copy/move operation you can follow these steps:

  • go to the "Files and Folders" page and create a property-based folder by using the folder which contains the file (the "MY_FILE" property)
  • create in this folder a File Removal operation which removes your file
  • assign the file removal to a component which will be installed by your package
Privacy Policy | Windows Installer | Search Engine Ranking | Link Analyzer