prasath_2k :
Hi,
> but the resultant array is coming as V.1.0.48 printed 4times!
The reason for this is the following:
-- Resulting array is declared as 'var arr = []' within the loop. This means that the array is recreated with every loop iteration and the previously created array gets disposed of;
-- Because array is declared using var (but not let) keyword array remains accessible outside of the loop;
-- While your 'for' loop iterates through the number of found files, you are pushing the same value into array on each loop iteration, thus you are getting four same values for the latest version to be printed to the log.
Considering the fact that installer file names are uniform, I would collect file names into an array, sort this array (this will sort file names in ascending or descending order - check this in debugger) and then use either first or last two array elements (depending on sort results).
Something like this:
let DTMFileItem;
let DTMName;
let arr = [];
while (DTMFiles.HasNext()) {
DTMFileItem = DTMFiles.Next();
DTMName = ...
arr.push(DTMName);
}
arr.sort();
// Depending on the sort results the latest installer file name will be either in
// arr[0]
// or
// arr[arr.length - 1]
// array element