Open Excel File without knowing the excel name through the folder path

So i am trying to open a excel file with a random name by using the file path. In my case, there are only 2 files in the folder, once is a pdf and the other is a xlsx. I want to open the .xlsx file.

Below is the path that i am using. In my case, “getMailDate” and “getMailTime” are folders, and in the last folder, i want to open the only excel file that is contained in that folder.

String.Format(“C:\Users\tallu\OneDrive\Documents\UiPath{0}{1}*.xlsx”, getMailDate, getMailTime)

But when i run my robot using that file path, it says illegal characters. I guess my question is how to format your string so that excel file will open. Thank you.

You can use Directory.GetFiles() with the SearchPattern option (String, String)

Example:
strFilePath = String.Format(“C:\Users\tallu\OneDrive\Documents\UiPath{0}{1}*.xlsx”, getMailDate, getMailTime)
Assign → listOfFiles (type String[]) = Directory.GetFiles(strFilePath, "*.xlsx")