parse string to get filename? urgent

okay I am trying to parse a string because I need both the filepath+location, and the filename itself.
ex.

Dim stripPath As String

stripPath = "c:\windows\file.txt"

How do I parse the string to get just    file.txt?

NOTE: the filename and paths will allways change.

ex:
strippath= "c:\file.txt"
strippath="c:\folder\beach.gif
strippath="c:\Program Files\MSN\msn.exe"

I want to be able to get just the file names from each path i want the string to return
ex:

file.txt
beach.gif
msn.exe
LVL 29
nffvrxqgrcfqvvcAsked:
Who is Participating?
 
vinnyd79Connect With a Mentor Commented:
Private Sub Command1_Click()
Dim stripPath As String

stripPath = "C:\windows\file.txt"

stripPath = Mid$(stripPath, InStrRev(stripPath, "\") + 1)

MsgBox stripPath
End Sub
0
 
GrahamSkanConnect With a Mentor RetiredCommented:
Try
vFileName = Split(srtipPath,"\")
strFileName = vFileName(Ubound(vFileName))
0
 
GrahamSkanRetiredCommented:
If you want to Dime the Variables, use
Dim vFileName as Variant
Dim strFileName as string
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Chris DentConnect With a Mentor PowerShell DeveloperCommented:
Hi,

stripPath = "c:\windows\file.txt"
arrPath = split(stripPath, "\")
strFileName = arrPath(UBound(arrPath))

HTH

Chris
0
 
Chris DentPowerShell DeveloperCommented:

I'm way too slow... nevermind, at least it's all the same.
0
 
vinnyd79Commented:
Or in a function:

Private Sub Command1_Click()
MsgBox StripPath("C:\windows\file.txt")
End Sub

Private Function StripPath(FilePath As String) As String
StripPath = Mid$(FilePath, InStrRev(FilePath, "\") + 1)
End Function
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.