The postings on this site are my own and do not represent my Employer's positions, advice or strategies.

LifeAsBob - Blog

 

Home

No Ads ever, except search!
Thursday, March 28, 2024 Login
Public

Parse File Name from path 11/20/2007 8:06:32 PM

Such a simple task, but one that trips me up each time.  I can do it very easily in TSQL, but sometimes i have to do it in .net scripting, vb or c#.

I tried using Regex below but was just too tired to fight beyound what I had...any help, the old vb.net standard function is what i ended up using...

Dim MyRegex as Regex = New Regex( "[^/]+$", RegexOptions.RightToLeft )

-------------

    Private Function GetNameNoPathorExt(ByVal FileNameWithPath) As String
        Dim sTemp As String
        Dim iPos As Integer

        iPos = InStr(FileNameWithPath, ".")
        If iPos > 1 Then
            sTemp = Left$(FileNameWithPath, iPos - 1)
        Else
            sTemp = FileNameWithPath
        End If

        iPos = InStrRev(sTemp, "\")
        If iPos > 1 Then
            sTemp = Right$(sTemp, Len(sTemp) - iPos)
        End If

        Return sTemp
    End Function


Blog Home