Tag Archives: get file path

Extract the file name from the complete file path

Sometimes there is a need to get the file name from the complete path name

Use the following function

If you pass URL as “http:/vbnet.redirect.com.au/defaul.aspx ” the following

function will return “default.aspx”

Function GetFileNamefromURL(ByVal URL String) As String
Return FILEPath.Substring(FILEPath.LastIndexOf("/") + 1)
End Function

In this function if you pass “c:\temp\myfile.txt” it will return “myfile.txt”

Function GetFileNamefromFileSystemPath(ByVal FILEPath As String) As String
Return FILEPath.Substring(FILEPath.LastIndexOf("\") + 1)
End Function