Write data in excel after a specific count

Hi Everyone,

I need some help in building a logic for below instance.
I have a list which contains excel file that can be any number like 1000, 2112 etc.
I am looping over each file and merging the data into one DT. Now what I require is that Bot should write that merge DT to a file in multiples of 500.
Example - If bot started from 1 when 500th file came bot wrote the merge DT into a file and again looped over the next set of 500 and appended the next set into the same file and then again over set of 500. In this manner bot should Loop over and write when file count is in multiples of 500.

Please help.

Thanks!

1 Like

Hey @Dhruvi_Arumugam

Take the output index from the For-each activity.

Use a condition at the end of For-each after processing a file,

For-each(file in fileList) out index
{
    //Your Logic

    If(index+1 mod 500 == 0)
    {
        //Write output file
    }
    Else
    {
        //Continue
    }
}

Hope this helps.

Thanks
#nK

Hi @Nithinkrishna,

thanks for your reply!!

One more thing after doing mod if we suppose there were 4523 files, then considering above solution 23 files will be left to be appended. So in that case in the else section can we use a condition like

Totalfilecount<500 then append

those left over files also ??

1 Like

Hey @Dhruvi_Arumugam

Sorry for missing that out,

For-each(file in fileList) out index
{
    //Your Logic

    If(index+1 mod 500 == 0 OrElse index+1 = fileList.Length)
    {
        //Write output file
    }
    Else
    {
        //Continue
    }
}

Thanks
#nK

Hi @Nithinkrishna,

One doubt here,
in the below condition

if we are supposing bot is working on 4523 files and as 4500 files would be covered in mod 500 == 0 scenario, how will 23 files covered in

like if we are saying that post 4500, 4523 will be equal to 4523 on the above condition and it will append the rest of the files?

Thanks

1 Like

Exactly the last batch.

Ok Thanks I will try this and let you know

1 Like

Cool done @Dhruvi_Arumugam :slightly_smiling_face::+1:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.