How to open a file with variable file-name?

I would like to know if it is possible to store a file name in a variable (it can be PDF, Excel, CSV etc) and open it for reading?

Means suppose a PDF file is generated with today’s date attached to its file name (say Document_08_16_2017.PDF).
Now suppose if I am able to get that file name generated through .NET script, how will I pass this dynamic file name to Read PDF Text activity?

Before getting name of file you must locate the file path then you could pass path.combine(“path”,“filename”) in the ReadPDFText Activity.

1 Like

Hi, I have a similar question - I have a variable created with a value of report name plus current date. In an excel scope, I want to open this report everyday. I want to use the variable as the file name to open. I have tried several variations but can not get it to open.

Variable: fileName is a variable with a value of "Report Name " + DateTime.Now.ToString(“MM-dd-yyyy”) + “.xls”

Excel Scope: "C:\Users\Documents\UiPath\ +“fileName”

Are you getting any error?
try below path.
“C:\Users\Documents\UiPath” +fileName

1 Like

Thanks - I tried and still does not open - no error - just opens a blank worksheet in excel.

Should add - I have it as an argument not a variable.

I don’t think so argument makes any difference here .Because as you mentioned its opening blank worksheet that bit wired isn’t it :thinking:
Are you sure there is file available in the following path containing data (having same file name?)

I really think it is my Excel. Today it opened the file, although it would not execute the macro. I have had other Excel issues as it relates to UiPath. Files from SAP saving unconverted even when spreadsheet is clearly defined - saving as .txt when the activity is selecting .xlsm. I am trying to work through these issues with our IT staff. Thanks for your help!

Hi i have a similar question iam.trying to pass a column value in excel name for example …filename%userid%.csv…How to do this…

Hi I have a Question i am trying to open text file file name is daily changing, file name like (notepad-Todaydate-45453.txt,notepad-Todaydate-34545.txt) how to open these files ?

take “todaydate” as a variable and then assign it DateTime.Now.ToString(“dd-MM-yyyy”) given the fact that you want the date in the format dd-MM-yyyy else DateTime.Now.ToString(“ddMMyyyy”) if ddMMyyyy

Thanks you

this works fine.

1 Like