Array Error

Hello, all

Could you please help for resolving “Index was outside the bounds of the array” error?
I’d like to store file data to ‘str_CurrentReport’
Logic is if there is no current month file, it should be copy from template form and pasted to destination path. and store the file to ‘str_CurrentReport’ variable


What is length of arr_files variable like 1 or 2?
Can you paste path that you’ve provided to directory?


@Pankaj.Patil Thank you for your reply!
here it is, when I add (0) at the end, I faced error. So, I’ve deleted.
Directory.GetFiles(“G:\Shared drives(int) P00433_Treasury_Cash_Report\01_Staging\Treasury_CashReport_Final”,““+Today.ToString(“yyyy-MM”)+”.xlsm”)


No issue…
path looks correct.
can you try with arr_files.item(0)?

Hi @Dorothy_lee,

By the message arr_files is empty and this error did occur on “Else” block.

In this point you are trying to access the first index of your array but I’m pretty sure it is empty here.

1 Like

Hi ! Thank you for your reply.
Understood that the variable at ‘else’ is empty field. How can I fix it…? Should I have to assign it another arr_variable?

@Dorothy_lee - Please print the arr_files using write Line activity using this code String.join(vbcr,arrfiles)…

If this month file not exist then your arr_files(0) will be empty right? So you can’t assign

What exactly you are trying to assign there??

Also, could you please share the directory.getfiles code too? if possible , if could you provide your full requirement ( i think i have been following from the beginning :wink: ) , I will try to build a sample flow for you…

Update: You have to do the directory.getfiles again and then you can assign str_currentreport = arr_files(0)…

@prasath17 Hello, Thank you for helps several times:)
I’ve attached my current project file. Could you please refer to Open this month file sequence?
What I try to do now is if possible I’d like to assign newly created file to same variable which is str_currentreport.
P00433_Report_Creation - (118.3 KB)

Helo @Dorothy_lee - I have reviewed the your workflow and understood what you are trying to do…

In the bol_First_Tue Else case, you are copying the template the file to the your Treasury_CashReport_Final folder and then renaming the file to Treasury_CashReport_Final" + now.ToString(“yyyy-MM”)+“.xlsm”). So now your template file Main_Template.xlsm will come 2021-05.xlsm and this is the file you are trying to allocate to str_CurrentReport variable right.

So I have added this code to the “str_CurrentReport”, because after you copied the file you have to sweep the directory again to check for the recent file right…?? or else you won’t get the file name from the folder…

Hope this helps…Please let us know, if this resolves your error…

1 Like

@prasath17 Hello!
I appreciate for your helps ! It’s working totally fine when I proceeded with your code.
Thank you so much

1 Like

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