#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2004
    Posts
    233
    Rep Power
    76

    Getting a filename from a string


    Hello, I have a list of .exe files and some of them have extra stuff at the end. I was wondering how to get the filename without the stuff at the end.

    Here is an example:
    Code:
    C:\Windows\system32\svchost.exe -k netsvcs
    C:\Program Files\Common Files\Symantec Shared\ccSvcHst.exe /h ccCommon
    C:\Windows\system32\dllhost.exe /Processid:{02D4B3F1-FD88-11D1-960D-00805FC79235}
    I'm not quite sure if regex is the best solution for this, but if it is, could somebody help me out? Thanks.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2004
    Posts
    233
    Rep Power
    76
    Well not sure if this is the best way, but it seems to work:

    [code=vb.net]Dim vFile As String = "C:\Windows\system32\svchost.exe -k netsvcs"
    Dim vFilePattern As New Regex("(.*?)\.(exe|dll|drv)", RegexOptions.IgnoreCase)
    Dim vMatches As MatchCollection = vFilePattern.Matches(vFile)
    If vMatches.Count > 0 Then
    Dim vMatch as String = vMatches.Item(0).ToString
    MsgBox(vMatch)
    End If[/code]

IMN logo majestic logo threadwatch logo seochat tools logo