Recursively empty directory - Advanced Installer Community

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!

ssearles
Posts: 65
Joined: Tue Oct 30, 2007 12:54 pm

Recursively empty directory

From within an installation routine, if i have a directory tree that I can identify with a wildcard (in this case it's a series of subdirs in a location that all start with 'a*') and want to simply clean out, but leave the folders in place.... how best would I be able to do that?
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Recursively empty directory

Hi,

I'm afraid that Windows Installer doesn't support this directly. However, you can try to use a Custom Action. This custom action would get the path of the parent folder (from a property for example), go through each folder and remove all files.

Unfortunately we don't have a sample custom action for this, but here you can find a sample custom action for finding and removing a file.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
canhuth
Posts: 241
Joined: Thu Jun 19, 2008 9:03 am

Re: Recursively empty directory

ssearles wrote:From within an installation routine, if i have a directory tree that I can identify with a wildcard (in this case it's a series of subdirs in a location that all start with 'a*') and want to simply clean out, but leave the folders in place.... how best would I be able to do that?
Hello ssearles,

in a custom action script written in Javascript or VBScript you can use the method FileSystemObject.DeleteFolder(...) (http://msdn.microsoft.com/en-us/library ... S.85).aspx) to delete directory trees.

You will have to get a list of all folders in the directory in question and check each wether its name starts with "a", and if it does execute FileSystemObject.DeleteFolder(...) for it and recreate it. Or get the list of the files and folders in those directories and issue DeleteFolder and DeleteFile respectively on each. Also, be prepared that the deletion might fail, and make your script handle this gracefully by catching exceptions, retrying, etc. :|

Be aware that scripting in Windows Installer is a little painful. Use exception handling and WScript.Shell.Popup(...) (http://msdn.microsoft.com/en-us/library ... S.85).aspx) and popup messages in case of errors while developing, if it becomes too confusing/frustrating to guess where it failed.



Bye bye

clemens

Return to “Common Problems”