SF said:
Hi,
I have file eg G:\MYPICTURES\123456.JPG
What is the function to strip the PATH (eg G:\MYPICTURES\) out of the
enture string?
If the file exists, you can use this simple function:
'----- start of code -----
Function PathOnly(FullFilePath As String) As String
PathOnly = _
Left(FullFilePath, _
Len(FullFilePath) - Len(Dir(FullFilePath)))
End Function
'----- end of code -----
If the file doesn't exist, you need to do a bit more work:
'----- start of code #2 -----
Function PathOnly2(FullFilePath As String) As String
'Use this version if the file may not exist.
Dim I As Long
I = InStrRev(FullFilePath, "\")
If I = 0 Then
I = InStrRev(FullFilePath, ":")
End If
If I = 0 Then
PathOnly2 = FullFilePath
Else
PathOnly2 = Left(FullFilePath, I)
End If
End Function
'----- end of code #2 -----