How to open excel file with wildcard mask (asterisk)

Dear all,

I would like to open specific excel file among several files.

"‘Date’ stock_*"



However, ‘Illegal characters in path’ was displayed.

Could you please help me to solve it…?

Hi @Printf7 – Assuming there is only one file gets created per day, then you can use the below to pull the file which created today…

StrFileName = Path.GetFileName(Directory.GetFiles(YourFolderPath,"*.xlsx").OrderByDescending(Function(d) New FileInfo(d).creationtime).First)

OR (If in case, the above code does not fetching the right file then use the below)

StrFileName = Path.GetFileName(Directory.GetFiles(YourFolderPath,"*.xlsx").OrderByDescending(Function(d) New FileInfo(d).LastWriteTime).First)

1 Like


Thank you for answering!

There are 2 types of data (sales, stock) in same folder.
Sales : Today’s data is necessary
Stocks : Yesterday’s data is necessary

I would like to select some specific file with Date and Keyword.

I searched it other article.

How can I set it to get the file that it begins with ‘date’ sales_ ?
example) “210318 sales_ …xlsx”

It didn’t work. There was no result.
“File path” + DateTime.Now.Date.ToString(“yyMMdd) + " sales_*.xlsx”. SearchOption.AllDirectories)

It works. However, I can’t select only sales data.
“File path” + DateTime.Now.Date.ToString("yyMMdd) + “*.xlsx”. SearchOption.AllDirectories)

@Printf7 - Here you go: to get today’s stock file

Yesterday's stock file

StrStockFiles = Directory.GetFiles(“Files”,“yyMMdd”)+"* stock *.xlsx")
Remove the space after the first * …added just to show in the text here…

To get both stock and sales files created yesterday…

Tomorrow's stock File

My Input Files Folder

1 Like

Dear sir,

It works well. :grinning:
I always appreciate about your professional advice!!! :+1: :+1: :+1: :+1:

1 Like

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