Short question: Is there any way to populate a FileSet using an Include Filter list that is populated at run-time?
Scenario:
I have multiple, deployable, 7-zip archives. The files that should be in each archive are stored in a file named *.lst. Each .lst file contains a set of filters defining the contents of the 7-zip archive, which each filter on a separate line. At run time, I want to iterate all of the .lst files, then build a FileSet containing the files that match the filters from the .lst file.
It would seem so easy using FileSets, File Contents Iterators, and Fileset Iterators. But I can't find a way of populating the FileSet Include Filters at run-time.
At this time the only way to populate the patterns and filters is at design time. I will look at adding scripting support so that it can be done at runtime… I can’t promise any timeframe at this stage… will have to look and see what is involved.
In case others are interested, here is what I'm attempting now:
I've created 14 "FileSpec" variables, named FileSpec1 through FileSpec14. I'm adding each of these as an Include Filter using the variable in the mask. I picked 14 because my largest list is 10 lines long but I don't want the script to break if a single line or two were added to the list.
The tricky part for me was getting the file contents into the variables. I'm using a File Contents Iterator to each line from the file (stored in a variable) to one of the FileSpec variables.
So in the OnBeforeEachIteration script event, I set a global FileSpecIteration = Iteration (event parameter value). This is a numeric index of the Iteration. Then I have a Set Variable action as a child of the File Contents Iterator, and in the BeforeAction event, I'm setting Action.VariableName = "FileSpec" & CStr(FileSpecIteration)
This is successfully setting each separate FileSpec variables to the corresponding line from the file. Be sure to initialize the FileSpec variables to a filename that will never be found, so that if file lists that are shorter do not end up adding wildcard masks to the Include Filter.
Still working on finishing the project, but I think this is going to work...
I should have a new build for you mid next week (Monday is a holiday here) with scripting support for fileset patterns and filters. I got half way through implementing it today but had other things to attend to.
Although my hack is working, I think scripting support for FileSet patterns and filters is long overdue. I see the OleVariant object available via script, but I have no idea how to use it (or if it can be used).
This build has the scripting support. I haven’t had chance to document some parts that will need documenting. The method to add filters can return objects of differing types, however the code completion parser has no way of knowing what types they are (and I didn’t want to hard code that in).
The trick is to give the code completion the type :
dim filter set filter = Action.FileSet.Filters.AddFilter(“Contains”) 'as FileSetFilterContains
Notice the [ ’ as FileSetFilterContains ] comment on the end of the liine
This gives the code completion engine the type for filter.