8831
asked on
Get the name of a file of a string containing the full path name
I have the full path name in a string variable, eg.:
strFileName = "C:\temp\filename.txt"
How do I extract only the filename from the string above, in this case that would be "filename" only?
strFileName = "C:\temp\filename.txt"
How do I extract only the filename from the string above, in this case that would be "filename" only?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Dim strPath As String
Dim strFileName As String
Dim backslashPos As Integer
strFullPathToFileName = "C:\temp\filename.txt"
backslashPos = InStrRev(strFullPathToFile
If backslashPos > 0 Then
strPath = Left(strFullPathToFileName
strFileName = Mid(strFullPathToFileName,
Else
strPath = ""
strFileName = strFullPathToFileName
End If
Debug.Print strPath
Debug.Print strFileName
Regards,
Idle_Mind