How to use wildcard for attachement file name?

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jan 2008
Posts: 35
Reputation: leokuz is an unknown quantity at this point 
Solved Threads: 0
leokuz leokuz is offline Offline
Light Poster

How to use wildcard for attachment file name?

 
0
  #1
Oct 24th, 2009
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:

  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
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 35
Reputation: leokuz is an unknown quantity at this point 
Solved Threads: 0
leokuz leokuz is offline Offline
Light Poster
 
0
  #2
Oct 24th, 2009
It doesn't have to be wildcards if there is a way to specify uknown part of the filename without wildcards.
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 94
Reputation: yorro has a little shameless behaviour in the past 
Solved Threads: 6
yorro yorro is offline Offline
Junior Poster in Training
 
0
  #3
Oct 24th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 35
Reputation: leokuz is an unknown quantity at this point 
Solved Threads: 0
leokuz leokuz is offline Offline
Light Poster
 
0
  #4
Oct 24th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 94
Reputation: yorro has a little shameless behaviour in the past 
Solved Threads: 6
yorro yorro is offline Offline
Junior Poster in Training
 
0
  #5
Oct 25th, 2009
  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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 35
Reputation: leokuz is an unknown quantity at this point 
Solved Threads: 0
leokuz leokuz is offline Offline
Light Poster
 
0
  #6
Oct 25th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 94
Reputation: yorro has a little shameless behaviour in the past 
Solved Threads: 6
yorro yorro is offline Offline
Junior Poster in Training
 
0
  #7
Oct 25th, 2009
Originally Posted by leokuz View Post
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

  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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 35
Reputation: leokuz is an unknown quantity at this point 
Solved Threads: 0
leokuz leokuz is offline Offline
Light Poster
 
0
  #8
Oct 25th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 94
Reputation: yorro has a little shameless behaviour in the past 
Solved Threads: 6
yorro yorro is offline Offline
Junior Poster in Training
 
0
  #9
Oct 25th, 2009
This would be your core code

  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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 35
Reputation: leokuz is an unknown quantity at this point 
Solved Threads: 0
leokuz leokuz is offline Offline
Light Poster
 
0
  #10
Oct 25th, 2009
Thank you!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC