944,101 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 2176
  • VB.NET RSS
Oct 24th, 2009
0

How to use wildcard for attachment file name?

Expand Post »
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:

VB.NET Syntax (Toggle Plain Text)
  1. Dim oAttch As Net.Mail.Attachment = New Net.Mail.Attachment("C:\test\102309LKO.pdf")
Last edited by leokuz; Oct 24th, 2009 at 12:17 am. Reason: typos
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
leokuz is offline Offline
36 posts
since Jan 2008
Oct 24th, 2009
0
Re: How to use wildcard for attachement file name?
It doesn't have to be wildcards if there is a way to specify uknown part of the filename without wildcards.
Reputation Points: 10
Solved Threads: 0
Light Poster
leokuz is offline Offline
36 posts
since Jan 2008
Oct 24th, 2009
0
Re: How to use wildcard for attachement file name?
So you want to attach a file using "C:\test\xxxxxxLKx.pdf"?

You can use .contains .
Last edited by yorro; Oct 24th, 2009 at 8:14 am.
Reputation Points: 8
Solved Threads: 7
Junior Poster
yorro is offline Offline
119 posts
since Aug 2009
Oct 24th, 2009
0
Re: How to use wildcard for attachement file name?
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.
Reputation Points: 10
Solved Threads: 0
Light Poster
leokuz is offline Offline
36 posts
since Jan 2008
Oct 25th, 2009
0
Re: How to use wildcard for attachement file name?
VB.NET Syntax (Toggle Plain Text)
  1. Dim oAttch As Net.Mail.Attachment = New Net.Mail.Attachment("C:\test\102309LKO.pdf").Contains("LK")
Last edited by yorro; Oct 25th, 2009 at 12:33 am.
Reputation Points: 8
Solved Threads: 7
Junior Poster
yorro is offline Offline
119 posts
since Aug 2009
Oct 25th, 2009
0
Re: How to use wildcard for attachement file name?
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.
Reputation Points: 10
Solved Threads: 0
Light Poster
leokuz is offline Offline
36 posts
since Jan 2008
Oct 25th, 2009
0
Re: How to use wildcard for attachement file name?
Click to Expand / Collapse  Quote originally posted by leokuz ...
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

VB Syntax (Toggle Plain Text)
  1. 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.
Last edited by yorro; Oct 25th, 2009 at 2:14 am.
Reputation Points: 8
Solved Threads: 7
Junior Poster
yorro is offline Offline
119 posts
since Aug 2009
Oct 25th, 2009
0
Re: How to use wildcard for attachement file name?
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.
Reputation Points: 10
Solved Threads: 0
Light Poster
leokuz is offline Offline
36 posts
since Jan 2008
Oct 25th, 2009
0
Re: How to use wildcard for attachement file name?
This would be your core code

vb Syntax (Toggle Plain Text)
  1. ' This would Save all Filenames in an array of string
  2.  
  3. Dim FileName(0) As String
  4. Dim x As Integer = 0
  5. For Each FoundFile As String In My.Computer.FileSystem.GetFiles("C:/Test/",FileIO.SearchOption.SearchTopLevelOnly, "*.pdf*")
  6. If FoundFile.Contains("LK") Then ' Or KL
  7. FileName(x) = FoundFile ' Saves filename to FileName String
  8. ReDim Preserve Filename(x+1) ' Adds another index to array
  9. x + = 1
  10. End If
  11. Next

You can mark thread as solved
Last edited by yorro; Oct 25th, 2009 at 2:32 am.
Reputation Points: 8
Solved Threads: 7
Junior Poster
yorro is offline Offline
119 posts
since Aug 2009
Oct 25th, 2009
0
Re: How to use wildcard for attachement file name?
Thank you!
Reputation Points: 10
Solved Threads: 0
Light Poster
leokuz is offline Offline
36 posts
since Jan 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: TCP Windows Mobile 6.1
Next Thread in VB.NET Forum Timeline: Adding Time to Splash Screen Help Please





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC