Can I read specific file which contains some words'?

Hello~

I’d like to open specific file which contains ‘cashreport’ word.
How can I configure…?
image

Current script : “D:\Users\01048398\Desktop\Treasury_CashReport\01_Input”+Contains(‘cashreport’)+".xlsx"

Hi @Dorothy_lee

Please try this syntax

Directory.GetFiles(“D:\Users\01048398\Desktop\Treasury_CashReport\01_Input”,"*.xlsx").Where(function(d) d.Contains(“cashreport”))(0)

it will open first xlsx file with cashreport word in it

1 Like

Hi @Dorothy_lee
adding little modification to @prasath_S answer ,
Directory.GetFiles(“D:\Users\01048398\Desktop\Treasury_CashReport\01_Input”,"*.xlsx").Where(function(d) Path.GetFileName(d).Contains(“cashreport”))(0)

Regards,

Nived N
Happy Automation

1 Like

@NIVED_NAMBIAR hello,
I’ve just tried but seems like I put wrong variable. Could you please give some advise on it?


This str_arr_HaNA variable should be string type. Not array of string.

As I noticed, your question is almost the same as here:

@Yameso oh ! Thanks! one of errors has been disappeared but remained below error message.!

@Yameso Resolved…haha :grinning:

ok, so basically:

Using Directory.GetFiles you are filtering files from specific location and as a result you will get array.

If you are sure that you always would get only one result than just use @NIVED_NAMBIAR solution:
Directory.GetFiles("D:\Users\01048398\Desktop\Treasury_CashReport\01_Input","*.xlsx").Where(function(d) Path.GetFileName(d).Contains(“cashreport”))(0)

In that case you will always choose first file from that array of strings (because of the “(0)” at the end of the code).

If you are not sure, if there is required file in that folder or it is possible that there is more than one, then you can just use similar option like in there: Can I open excel file based on current Month information? - #7 by Dorothy_lee

@Yameso I see. Well understood. Thank you so much for further explanation !

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