Solved

Split values

Posted on 2007-03-21
2
179 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
  • 2
2 Comments
 
LVL 49

Accepted Solution

by:
Ryan Chong earned 500 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 49

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now