How can I use wildcard/s for the attachment filename. Part of the filename changes but the characters 8 and 9 (counting from the left to right) always present and always either LK or KL. Currently files are PDF type, thus with extension PDF but might be different in the future (this is not important now). Please help. Thank you!

Here it is:

Dim oAttch As Net.Mail.Attachment = New Net.Mail.Attachment("C:\test\102309LKO.pdf")

Edited 7 Years Ago by leokuz: typos

It doesn't have to be wildcards if there is a way to specify uknown part of the filename without wildcards.

So you want to attach a file using "C:\test\xxxxxxLKx.pdf"?

You can use .contains .

Edited 7 Years Ago by yorro: n/a

You understood me exactly right, but would you be able to show me an example of using contains? I know less than you may think. Thank you.

Dim oAttch As Net.Mail.Attachment = New Net.Mail.Attachment("C:\test\102309LKO.pdf").Contains("LK")

Edited 7 Years Ago by yorro: n/a

yorro, you have specified in this statement ("C:\test\102309LKO.pdf").Contains("LK") complete file name, but the problem is that I am dealing with files that while I know contain LK or KL, but I do not know what are the other six characters that preceed LK or KL (from left to right). The filenames are different everyday and the first six characters correspond to current date like you have suggested (e.g. if file for example created today, then it is 102409LK????.pdf, etc. ). So, how I address the mentioned uknown part of the filename?

Thank you for your time.

yorro, you have specified in this statement ("C:\test\102309LKO.pdf").Contains("LK") complete file name, but the problem is that I am dealing with files that while I know contain LK or KL, but I do not know what are the other six characters that preceed LK or KL (from left to right). The filenames are different everyday and the first six characters correspond to current date like you have suggested (e.g. if file for example created today, then it is 102409LK????.pdf, etc. ). So, how I address the mentioned uknown part of the filename?

Thank you for your time.

You can try to search all files in a folder with .pdf as filename

Filename As String = My.Computer.FileSystem.GetFiles("C:\test\",FileIO.SearchOption.SearchTopLevelOnly, "*.pdf*")

Then proceed to filter for each file name found using .Contains("LK")

You can look up the DIR function and FILEIO in MSDN.

I think searching for all files not only .pdf, you will use GETFILES function.

Edited 7 Years Ago by yorro: n/a

Thanks. You gave me enough clue to solve the problem. I think that if I can search pdf files, then I should be able to find files with LK or KL.

Thank you again.

This would be your core code

' This would Save all Filenames in an array of string

Dim FileName(0) As String
Dim x As Integer = 0
For Each FoundFile As String In My.Computer.FileSystem.GetFiles("C:/Test/",FileIO.SearchOption.SearchTopLevelOnly, "*.pdf*")
    If FoundFile.Contains("LK") Then ' Or KL
    FileName(x) = FoundFile ' Saves filename to FileName String
    ReDim Preserve Filename(x+1) ' Adds another index to array
    x + = 1
    End If
Next

You can mark thread as solved

Edited 7 Years Ago by yorro: n/a

This question has already been answered. Start a new discussion instead.