How do I add items in an array

  • 7 November 2023
  • 2 replies

Userlevel 1

I have following script:


<arc:set attr="Files#1">[FilePath]</arc:set>
<arc:call op="xmlDOMSearch?uri=[FilePath]&xpath=/Items/File">
<arc:set attr="Files#[_index | add(1)]">SOME_FILEPATH\[xpath('FileName')]</arc:set>

<arc:enum attr="archiveFiles" expand="true">
<arc:set attr="">([_index]) [_attr] -> [_value]</arc:set>


Whatever I try, the enumeration only shows the first item.  If I add a arc:set="” in the arc:call, each item is logged, but for some reason it is not added in the array.


The reason I want to add these files in an array is that I want to compress them all in 1 ZIP file.


Best answer by James B 7 November 2023, 21:23

View original

2 replies

Userlevel 5

The attr that you are enumerating here doesn’t match the attr of the same name that you are setting in the top line of code, but I’ve prepared an example here to show you how the enum works. First, I’m going to use a simply enum to populate an array:


<arc:enum list="red,orange,yellow,green,blue,indigo,violet" sep=",">
<arc:set attr="tmp.colors#" value="[_value]" />

A few points here:

  • It’s recommended that when working with attrs, you declare an explicit item that they are members of (tmp here). This is akin to defining a class where the attr is defined as a member of
  • When adding to an array, you can specify the index directly as you did in your sample, but when an index is not specified as above, you will always add the element to the end of the array


This array, once populated, can be enumerated using the attr keyword to arc:enum:


<arc:enum attr="tmp.colors">
<arc:set attr="">([_index]) [_attr] -> [_value]</arc:set>


This enum returns multiple results for each member of the array, and the end result of this would be:


Info ~/resource://script.rsb (7) colors#7 -> violet
Info ~/resource://script.rsb (6) colors#6 -> indigo
Info ~/resource://script.rsb (5) colors#5 -> blue
Info ~/resource://script.rsb (4) colors#4 -> green
Info ~/resource://script.rsb (3) colors#3 -> yellow
Info ~/resource://script.rsb (2) colors#2 -> orange
Info ~/resource://script.rsb (1) colors#1 -> red


NOTE: The script in use here has already been addressed in a separate thread with support. 

Userlevel 1

Thank you for your reply.


I searched for the solution before creating this ticket, but did not find any matches.