
Parsing filename and path
Quote:
> Hi,
> I have used theGetOpenFilename method to get a filename. This returns the
> full path and filename of the file to one variable. Is there an easy way to
> parse the path and filename and assign them to two different variables?
> Do I have to search for a "/" string and find its position? if so how do I
> get the position of the last / and not the first?
> Any assistance will be appreciated.
> Thank you.
> Sean Bartleet
Might want to try this:
' Splits a file name and path into its seperate parts
Public Sub FileNameSplit(ByVal pstrFile As String, pstrPathPart As
String, pstrFilePart As String)
pstrFile = Trim(pstrFile)
pstrFilePart = FileNamePart(pstrFile)
If Len(pstrFilePart) > 0 Then
pstrPathPart = Left(pstrFile, Len(pstrFile) -
Len(pstrFilePart))
Else
pstrPathPart = pstrFile
End If
If Right(pstrPathPart, 1) = "\" Then pstrPathPart =
Left(pstrPathPart, Len(pstrPathPart) - 1)
End Sub
Regards
Graham
--------------
Progressive Data Solutions
http://www.pdsolutions.com.au
Home of VB Code Cutter - VB/VBA Code Library, Dev Tool with Free code
formatting/indenting