How to read a file ignore its suffix

Hi there, could you pls advise how to set parameters to read a file that start with “open order report”, because my file name is “open order report_8-12-2020”, I don’t want to change the file name everyday. Thank you!

1 Like

Hi @learningRPA welcome to forum,

You want to read only date only from file name

Nived N :robot:

@learningRPA please try this which returns string array
FileArray = Directory.GetFiles(path,“open order report*”)

1 Like

Hello Nived, I want to read the name, ignore the date.


Hi RRkadari, I uploaded the pic, currently I will delete the date before run the Uipath,
is there any way to run automatically? thank you!

Hi @learningRPA

Do this way to get the file name by using Path.GetFileName( filepath) and store it in a variable, let’s say name
Use if condition , in condition put name.Contains(“open order report”), if it is true in then section , open file ( like what u had shown in screenshot now)

If under a loop like when u are working with multiple files, using this condition, then in else section, u can use continue activitiy so that it got to next file if the condition didn’t met true

Hope u got the logic

Mark it as a solution if it helps

Nived N :robot:

Happy Automation :relaxed:

Hi Nived, it works, but when I add excel application after this step, how to fill the workbook path?
path.tostring didn’t work.

Hi @learningRPA,
you can use something like ‘open order report_"+date.today.tostring(“MM-dd-yyyy”)’ as filename in the read range activity. So UiPath will use today’s date on your filename. If your report has always a date different to today, you can insert ‘addday(-1)’ like ‘open order report_"+date.today.AddDays(-1).tostring(“MM-dd-yyyy”)’.

Moritz

Hi Moritz, thank you!
I have 2 scenqrios:

  1. open order report_9-4-2020
  2. open order report_4Sep2020
    could you pls tell me how to write the path.

Hi @learningRPA
Sorry for delayed response

In the if condition, if the file name contains open order report then in then condition ,
Use the workbook activity to open that file path, ie as described above as name variable which stores the file path

Hope you got it

Regards

Nived N :robot:

Happy Automation :relaxed::relaxed:

Hi,
it is all in the formatting expression. With
‘open order report_“+date.today.tostring(“M-d-yyyy”)’
you will get just one digit for the first 9 days. And with
‘open order report_”+date.today.tostring(“dMMMyyyy”)’
you will have the name of the month.

Please note, that you need ‘MM’ for the month, ‘mm’ gives you the minute of a datetime variable.
And add ‘-’ or ‘:’ or ‘_’ or what else between day, month and year as you need it.

Hope it helps!
Regards
Moritz

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