Monday, March 26, 2012

Foreach From Variable using 2 dim array variable

Is there any way to use a 2 dimensional array of strings as the Variable Enumerator for the "Foreach From Variable Enumerator". I am trying to copy a collection of files from folder A to folder B. In a script, I would populate, let us say, an array of (2,10), for 10 files, with one column representing the source file and other column representing the target column task. Then I would like to set this string array variable as the "Variable Enumerator" for the "Foreach From Variable Enumerator" and use file system tasks in the foreach loop to perform the tasks. The problem is that the "Foreach From Variable Enumerator" does not let me choose an index, but passes only one index 0, so, I will only be able to pass just one column. How do I let the foreach enumerator let me choose an index. The other foreach enumerators, foreach item and ADO give me the option to select index. I would like the same functionality in the foreach variable.

Note: I cannot use the "For Each File" enumerator, since the files are to be selected by a script only.
Thanks for the help.

I found a work around by concatenating the variables with a delimiter and then stripping them in a script in the foreach loop. It works ok.|||

When you want more than one variable in enumerator, use a matrix (multi-index) enumerator, of which there are at least two types. The Foreach Xml can be a matrix enumerator, as can the ADO enumerator. In the first case, build an Xml document which represents your data as in

<surveys>

<survey>

<question/><!-- this is index 0 -->

<answer/><!-- this is index 1 -->

.....

For the Foreach ADO matrix enumerator, a very similar option is to build a DataTable object which has multiple columns, load the DataTable with whatever data you want (doesn't need to be from a database), and then use it in the Foreach ADO enumerator, again with multiple indices.

No comments:

Post a Comment