[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

parse string to get filename? urgent

Posted on 2005-04-18
6
Medium Priority
?
298 Views
Last Modified: 2010-05-02
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
0
Comment
Question by:nffvrxqgrcfqvvc
  • 2
  • 2
  • 2
6 Comments
 
LVL 76

Assisted Solution

by:GrahamSkan
GrahamSkan earned 200 total points
ID: 13805599
Try
vFileName = Split(srtipPath,"\")
strFileName = vFileName(Ubound(vFileName))
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 13805607
If you want to Dime the Variables, use
Dim vFileName as Variant
Dim strFileName as string
0
 
LVL 71

Assisted Solution

by:Chris Dent
Chris Dent earned 200 total points
ID: 13805612
Hi,

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

HTH

Chris
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 28

Accepted Solution

by:
vinnyd79 earned 600 total points
ID: 13805623
Private Sub Command1_Click()
Dim stripPath As String

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

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

MsgBox stripPath
End Sub
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 13805625

I'm way too slow... nevermind, at least it's all the same.
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 13805649
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question