|
Visual Basic (VB and VBA) |
|
Copyright 1999-2001 Christopher Greaves. All rights reserved. Home Page and email to [email protected] |
| If in doubt, record a macro and inspect the entrails! |
Please read the DISCLAIMER.
Here is an INDEX to all the procedures.
You will probably need one copy of my GLOBAL DECLARATIONS.
Public Function strGetFilenameFromPath(ByVal strFullPath As String) As String
'created by Charlotte Foust
'modified 2/15/2001 - added test for "." in strFullPath
'returns the filename from a path and filename
Dim strFileName As String 'holds name of file
Dim intLength As Integer 'holds the length of the string
Dim intLoop As Integer 'controls stepping through string
'only continue if a value passed
If strFullPath <> "" Then
'return the filename if the path is valid
strFileName = Dir(strFullPath)
End If 'strFullPath <> ""
'if the path is not valid, parse it out
If strFileName = "" And InStr(strFullPath, strcExtentSeparator) <> 0 Then
'if the path is not accessible
'use the string to the right of
'the last "\" in the full path
intLength = Len(strFullPath)
For intLoop = intLength To 1 Step -1
If Mid(strFullPath, intLoop, 1) = "\" Then
strFileName = Mid(strFullPath, intLoop + 1)
End If 'Mid(strFullPath, intLoop, 1) = "\"
Next intLoop ' = intLength To 0 Step -1
End If 'strFilename = "" And _
InStr(strFullPath, strcExtentSeparator) <> 0
strGetFilenameFromPath = strFileName
'Sub TESTstrGetFilenameFromPath()
'MsgBox strGetFilenameFromPath("d:\my documents\all this.txt") ' "d:"
'MsgBox strGetFilenameFromPath("d:\my documents\all this.txt") ' "my documents"
'MsgBox strGetFilenameFromPath("d:\my documents\all this.txt") ' "all this"
'MsgBox strGetFilenameFromPath("d:\my documents\all.txt")
'MsgBox strGetFilenameFromPath("d:\my documents\all this.txt") ' "txt"
'End Sub
End Function 'GetFilenameFromPath( ByVal strFullPath As String) As String
| We all knew nothing when we started … |
|
Home Page and Contact Information Send email to [email protected]. This page was last updated Thursday, November 15, 2001 |