We’re moving our forums to a new platform.

You can still browse and search existing topics, but you can no longer create new topics or post replies.

For questions, technical issues, or feature requests, please don’t hesitate to contact our support team at support@advancedinstaller.com.

Thank you for your understanding!

cmbourqu
Posts: 17
Joined: Tue Dec 18, 2007 9:19 pm

Delete the content of a folder

I want build an Installer that update a folder with new files:

1) delete current files in this folder
2) replace it by new files

It's a folder that contains other information e.g. differents files that will be installed.
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Delete the content of a folder

Hi,

Since the new files are installed by your package, the problem is the way you want to handle the existing files.

If you want to overwrite the existing files and you don't need to actually remove some of them, you can set a high temporary version for the files in your package. This can be done by using the "Ensure that this file overwrites any installed target file" option in the Version tab of the "Edit File" dialog.

If you know the names of the files you want to remove and you also know the exact path of the folder, then you can use File Removal operations. If you don't know the path of the folder which contains the files then you can create a Search for it. The result of the search (which is an installer property) can be used for a property-based folder which will contain the file removal operations.

However, if you don't know how many files are in the folder or you don't know their names, you can use a custom action which deletes the entire folder. Here is a sample custom action:

Code: Select all

Function removeDir()
   Dim pathToFolder, smallPath
   Set objFS = CreateObject("Scripting.FileSystemObject")
   pathToFolder = Session.Property("PROPERTY")   
   smallPath=Left(pathToFolder,Len(pathToFolder)-1)     
   If (objFS.FolderExists(smallPath)) then
      objFS.DeleteFolder smallPath, true     
   End if
End Function
where "PROPERTY" is the installer property which contains the path of the folder.
This code can be copy/pasted into a .VBS file and modified for your project (set the property you are using in your project). The custom action can be scheduled under the "RemoveExistingProducts" standard action in the "Custom Actions" page. You can see "RemoveExistingProducts" by using the "Show Standard Action" button on the toolbar.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
cmbourqu
Posts: 17
Joined: Tue Dec 18, 2007 9:19 pm

Re: Delete the content of a folder

Thanks a lot!
For suggestions, for excellent service!
jledhead
Posts: 9
Joined: Thu May 08, 2008 1:22 pm

Re: Delete the content of a folder

I am trying to do this right now and having some difficulty. I have created the vbs script and my msi runs just fine, but from the run and log, it doesn't seem to even be running the vbs script. I have added a custom action by going to custom actions, right click installExecuteSequence and adding RemoveExistingProducts. then I added an attached custom action to the removeexistingproducts and added my vbs file. I change the Function Name to be blank, then saved, built and tested my msi.

If the folder isn't there then my msi installs the files as desired, if the folder is there then it doesn't do anything. Any help is appreciated.
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Delete the content of a folder

Hi,

Did you modify the script for your custom folder? Note that the "PROPERTY" installer property must be replaced with a property which contains the path to the folder you want to delete. If you modified the script and the problem persists, please send us the AIP and VBS file to support at advancedinstaller dot com so we can investigate them.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
jledhead
Posts: 9
Joined: Thu May 08, 2008 1:22 pm

Re: Delete the content of a folder

sorry for posting this under feature requests. I did a search and found it and just went with it.

So when you say replace PROPERTY, you don't mean change property to c:\nameoffolder, you mean I need to create a property somwhere and then reference that here?
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Delete the content of a folder

Hi,

Since the custom action uses the Session object (Session.Property("PROPERTY")), you need to replace the property I used ("PROPERTY") with a custom property which contains the path to the folder you want to remove. If you want to use a hard-coded path, you need to remove the Session object:

Code: Select all

pathToFolder = "C:\My_Folder"
Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Feature Requests”