foreach reading variable wrongly



  • Avatar

    Can you paste an example of output and the code using in the foreach?

  • Avatar

    The <foreach> action should be used to iterate over lists generated by InstallBuilder. The issue you may be facing is with \, " or space characters.

    If you are generating a list of files where each line is a new file name, <foreach> is not the best way to go. You can use <while> and regular expressions to parse this (and most) formats of data:

    <!-- remove any trailing and leading newlines/spaces --> <stringModify> <text>list_of_files</text> <variable>${list_of_files}</variable> </stringModify> <!-- loop while there are any files left -- <while> <conditionRuleList> <compareTextLength> <length>0</length> <logic>greater</logic> <text>${list_of_files}</text> </compareTextLength> </conditionRuleList> <actionList> <!-- check if there are more entries; if so, use regexp to extract current and remaining items, otherwise set current file to the last line and set list_of_files to empty --> <if> <actionList> <setInstallerVariableFromRegEx> <name>current_file</name> <pattern>^(.*?)\n(.*)$</pattern> <substitution>\1</substitution> <text>${list_of_files}</text> </setInstallerVariableFromRegEx> <setInstallerVariableFromRegEx> <name>list_of_files</name> <pattern>^(.*?)\n(.*)$</pattern> <substitution>\2</substitution> <text>${list_of_files}</text> </setInstallerVariableFromRegEx> </actionList> <conditionRuleList> <regExMatch> <logic>matches</logic> <pattern>^(.*?)\n(.*)$</pattern> <text>${list_of_files}</text> </regExMatch> </conditionRuleList> <elseActionList> <setInstallerVariable> <name>current_file</name> <value>${list_of_files}</value> </setInstallerVariable> <setInstallerVariable> <name>list_of_files</name> <value></value> </setInstallerVariable> </elseActionList> </if> <!-- sample operation to do on a single item --> <showInfo> <text>F='${current_file}'</text> </showInfo> </actionList> </while> If your output is not line based, can you paste the script used to generate the list of files and/or sample output?

Please sign in to leave a comment.