leecett
asked on
Extract filename from full path
Experts
I have a variable which contains the full file path for a file, example below:
C:\Documents and Settings\leecett\My Documents\output.txt
I want to extract the filename (without the file extension).
Note, the filename may contain other full stops / periods (e.g. output.one.txt), but will always have a file extension of .txt.
So I have a variable:
strFilePath = C:\Documents and Settings\leecett\My Documents\output.one.txt
I want a variable:
strFileName = output.one
Thanks leecett
I have a variable which contains the full file path for a file, example below:
C:\Documents and Settings\leecett\My Documents\output.txt
I want to extract the filename (without the file extension).
Note, the filename may contain other full stops / periods (e.g. output.one.txt), but will always have a file extension of .txt.
So I have a variable:
strFilePath = C:\Documents and Settings\leecett\My Documents\output.one.txt
I want a variable:
strFileName = output.one
Thanks leecett
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
also try:
Dim temp As String, strFileName As String
temp = split(strFilePath, "\", vbBinaryCompare)
strFileName = Ubound(temp())
Dim temp As String, strFileName As String
temp = split(strFilePath, "\", vbBinaryCompare)
strFileName = Ubound(temp())
now with missing comma
Dim temp As String, strFileName As String
temp = split(strFilePath, "\", ,vbBinaryCompare)
strFileName = Ubound(temp())
Dim temp As String, strFileName As String
temp = split(strFilePath, "\", ,vbBinaryCompare)
strFileName = Ubound(temp())
ASKER
Thanks to you all for your advice and solution, I have developed the following:
Sub findfilename()
Dim strFilePath As String
Dim strFileName As String
strFilePath = "C:\Documents and Settings\leecett\My Documents\output.one.txt"" "
strFileName = Mid(strFilePath, (InStrRev(strFilePath, "\")) + 1, (InStrRev(strFilePath, ".") - (InStrRev(strFilePath, "\") + 1)))
End Sub
Many thanks
leecett
Sub findfilename()
Dim strFilePath As String
Dim strFileName As String
strFilePath = "C:\Documents and Settings\leecett\My Documents\output.one.txt""
strFileName = Mid(strFilePath, (InStrRev(strFilePath, "\")) + 1, (InStrRev(strFilePath, ".") - (InStrRev(strFilePath, "\") + 1)))
End Sub
Many thanks
leecett
=RIGHT(A1,LEN(A1)-FIND("|"
jppinto