How to open a file with a range of days?

Im currently opening an excel sheet that has a date in the name, and it is sent out every monday.

The current method i am using =

Assign activity : [currentDate] = [DateTime.Now.ToString(“yyyy-MM-dd”)]

Then i open the excel which is something like “Report-2018-06-14.xlsx” in the following manner =

“\resources\Report-” + currentDate + “.xlsx”

Which works great if I want to only open today’s report. the problem is the report might come in on a Monday or a Tuesday, so I was thinking of running the bot on a Weds.

as the report can come on a monday or tuesday i need a range of days, ideally like “Today + last 2 days”

I’ve tried

“\resources\Report-” + currentDate (-2) + “.xlsx”

but it didn’t work. I’ve also tried changing the assign & various other ways from google but i just cant seem to get it working.

any ideas? do i have to do the entire process in a differnt way to achieve this?

@Zak_Cooper Try currentDate.AddDays(-2).ToString or currentDate.AddDays(-2)

@Manjuts90 its returning the error ".AddDays is not a member of ‘string’.

i shouldve mentioned, “currentDate” is a string variable, should i set it to something else?

@Zak_Cooper Check attached file

LastTwoDays.xaml (5.1 KB)

1 Like

That works @indra thank you,

but the problem I have is trying to open the excel sheet based off that?

“Resources\Report-” + v1 + “.xlsx”

Any idea how i can go about this?

EDIT : If it makes life easier, i am getting the reports via an outlook folder using the “get outlook mail” and a “foreach mail → save attachment”

I dont know if there is a way to validate the report in that area that would be easier?

@Zak_Cooper You can open excel sheet by using “Resources\Report-” + v1 + “.xlsx” this dynamic path but pass this value in assign activity curr_date.AddDays(-2).ToString(“dd-MM-yyyy”)

1 Like

that will only work for files exactly 2 days ago,

What im trying to achieve is a range,

So lets say I run the bot every weds.

and one week 1 + 2 i receive the report on mon

on week 3 i receive the report on tue

and week 4 i receive the report on weds.

So my goal is to have uipath open an excel file that has the date in the name,

open excel scope → if file name contains today, yesterday or the day before date → open

Whats happening with your way is it cannot find the file from 2 days ago, so it creates a new file. But i have a fie from yesterday i would like it to find instead.

I wonder if its possible via a for each ? "for each file in X folder if name contains = today.AddDays(-2) then assign name to a variable, then open excel sheet using that variable ?

Is this a possibility ? or am i completely wrong?

@indra so what ive done is used your syntax ,

assign today = today
assign yesterday = yesterday
assign 2 days ago = 2 days ago

then ive done a “directory.getfiles” to string list

and finally a “for each” item in list → “if” item contains “today” or “yesterday” or “2 days ago” assign list item to string variable

And finally, excel scope = open “string variable” :slight_smile:

I dont know if its the best way, but it works! thank you for your help it allowed me to get there in the end.

1 Like