ThinApp cleanup with ExcludePattern

The last couple of days there was quite a bit of ThinApp news !

Time to post another ThinApp-PowerShell function.


With the ThinApp SDK you have to possibility to “query” your ThinApp packages from PowerShell. See my earlier Using the ThinApp SDK from PowerShell post for more info.

One parameter you can use in the package.ini file for a ThinApp package is the ExcludePattern. This parameter allows you to “…excludes files or directories during the application build process“. Which is a good idea, since we want to keep our ThinApp packages as slim as possible.

The obvious filetype candidates, and they appear in the examples in the ThinApp Package.ini Parameters Reference Guide and in Peter’s book, are .MSI and .CAB. When these type of files appear in a %temp% or in an Installer folder, it is obvious that you can remove them. But if there are some .MSI or .CAB files in other folders, then the decision is not so obvious.

The following script will help you investigate your existing packages, it will scan them for the filetypes you specified and report where these files were found.

The script


Line 21: The name(s) of the repositories can be passed on the Repository parameter, which also accepts pipeline input.

Line 27-34: Scanning through a directory tree structure is by definition a recursive process. This small helper function, called Get-TAFilesInFolder, handles the recursive part. It will scan a specific folder if there are subfolders, and if yes, the function will call itself with that subfolder. Then it checks all the files in the folders and will only return the ones that are of the specific filetype.

Line 37: The FileType parameter needs to be converted to a RegEx expression so the -match operator can be used to filter the correct files.

Line 42: The outer loop looks recursively at each entry passed through the Repository parameter.

Line 43: The function looks at all the .EXE and .DAT files

Line 44: … and checks if they are ThinApp files.

Line 48: Starting from the “root” of the package’s filesystem, the function returns all files of the specified type.

Line 49-55: For each file that meets the specifications the function returns an object in the pipeline

Sample Run

The function is quite simple to use, just provide one or more ThinApp repository paths and specify which filetypes you want to look for. The result can be stored in a CSV file for reference.

Note that I used a Select-Object before the Export-Csv cmdlet to guarantee the order of the exported properties. Note that this is not required anymore in PowerShell v3.
The resulting CSV file shows you clearly where the .MSI and .CAB files are located, and if it is safe to use the ExcludePattern parameter globally.

Time to start inserting this ExcludePattern parameter and do a rebuild !

I succeeded in saving more than 1GB of storage on a small ThinApp repository of some 20 packages.

Enjoy !

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.