09-03-2026 05:24 AM
Hi all,
I have a folder containing files which i would like to filter in order to obtain the next serial number which does not exist yet. The filenames are built with the format [serial number]_[date and time]. Sometimes there are multiple data files with the same serial number but that is fine and should be ignored.
In my sample vi (which does not work because each serial number is being matched to a single element of the array each time so there will never be correct matches), my goal is to compare the current serial number to every element in the filename array, if there is a match, to ignore it, increment the serial number and repeat (and stop when it reaches a certain maximum serial number) until it finds a serial number with no matches (which means the file does not yet exist) and gives that out to the user.
I have tried using a for loop as well but I couldn't get it to work too. The existing filename array is also bound to be larger than the quantity index so I also have to figure how to continue iterating according to the larger array.
I know I'm missing a certain loop logic here but I can't quite get it to work so any solution/tips are welcome.
Thank you in advance!
Solved! Go to Solution.
09-03-2026 05:44 AM - edited 09-03-2026 05:45 AM
Hi nikvi,
@nikvl wrote:
I know I'm missing a certain loop logic here but I can't quite get it to work so any solution/tips are welcome.
Please:

09-03-2026 06:07 AM
Hi GerdW,
thank you for the prompt reply!
Unfortunately that also did not work.
When I ran your code, it returned 25900441 as a result but it should be returning 250900447 since no file with that name exists yet.
09-03-2026 06:25 AM
Oh wait I found a typo in my serial numbers.
I changed the output wire of the found serial to before the addition function +1 to get the right serial number.
Thank you!
09-03-2026 08:17 AM
Hi nikvi,
@nikvl wrote:
I changed the output wire of the found serial to before the addition function +1 to get the right serial number.
You're right, you need to take the serialnumber value before incrementing to get the right output. (Or decrement after the outer loop.)
09-11-2026 02:44 AM
You can use some Decimal String to Number behaviours to simplify the code.