?
Solved

Split values

Posted on 2007-03-21
2
Medium Priority
?
196 Views
Last Modified: 2010-04-30
Hi: Can any one please tell me how to i split file name and folder from the variable
filetext.text = "C:\Documents and Settings\khamu443\My Documents\test.txt"

so it would be
filename="test.txt"
folderaddress="C:\Documents and Settings\khamu443\My Documents\"

Thanks.
0
Comment
Question by:mustish1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 53

Accepted Solution

by:
Ryan Chong earned 2000 total points
ID: 18764345
try:

Public Function getDir(filePath As String, Optional separator As String = "\") As String
    Dim tmp As String, I As Long
    tmp = StrReverse(filePath)
    I = InStr(1, tmp, separator)
    If I > 0 Then
        tmp = StrReverse(Mid$(tmp, I))
    Else
        tmp = ""
    End If
    getDir = tmp
End Function

Public Function getFileName(filePath As String, Optional separator As String = "\", Optional removeExtension As Boolean = False) As String
    Dim tmp As String
    tmp = Mid$(filePath, InStrRev(filePath, separator) + 1)
    If tmp = filePath Then
        getFileName = ""
    Else
        If removeExtension Then
            If InStrRev(tmp, ".") > 0 Then
                getFileName = Left$(tmp, InStrRev(tmp, ".") - 1)
            Else
                getFileName = tmp
            End If
        Else
            getFileName = tmp
        End If
    End If
End Function
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 18764393
Here is an example:

filetext.Text = "C:\Documents and Settings\khamu443\My Documents\test.txt"
    filename = getFileName(filetext.Text)
    folderaddress = getDir(filetext.Text)
   
    MsgBox "filename: " & filename & vbCrLf & "folderaddress: " & folderaddress


hope this helps
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

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

741 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