by Barabas Andrei (3 Submissions)
Category: Files/File Controls/Input/Output
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sun 7th January 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)
This is a function that extracts the Filename (with or without the extension) from the path.
'This .bas file was created by Barabas Andrei
'You can use it without deleting this header
'
'To use this function, you have to provide the
'path of the file
'if you want to extract only the name (without the
'extension, you have to call the function like this
'
'Ex: FileName("C:\Windows\setup.bmp",true) => "setup"
'
'else use the function like this
'
'Ex: FileName("C:\Windows\setup.bmp",false) => "setup.bmp"
'===========================================
Public Function FileName(ByVal path As String, ByVal t As Boolean) As String
Dim y As Integer
y = 1
While Left$(Right$(path, y), 1) <> "\"
y = y + 1
Wend
path = Right$(path, y - 1)
If t Then
y = 1
While (Left$(Right$(path, y), 1) <> ".") And (y <= 4)
y = y + 1
Wend
If (Left$(Right$(path, y), 1) = ".") Then
path = Left$(path, Len(path) - y)
End If
End If
FileName = path
End Function
No comments have been posted about This is a function that extracts the Filename (with or without the extension) from the path.. Why not be the first to post a comment about This is a function that extracts the Filename (with or without the extension) from the path..