[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Just the dir name not the whole path

Posted on 2003-11-21
4
Medium Priority
?
273 Views
Last Modified: 2010-05-03
Hello I'm using the DirListBox in my latest program but I have a little problem.
The data stored in the dir1 contains the whole path to a directory.
I only need the chosen directory.
Example:

dir1 = "C:\Documents and settings\all users\Desktop\"

I want just "Desktop" to be stored in a variable somehow.
I have a few ideas how I could do this and I'm sure they would work but it would be
MUCH work. So maybe someone here knows a fast efficient way to do this.
0
Comment
Question by:Shibjuh
[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
4 Comments
 
LVL 11

Accepted Solution

by:
dbrckovi earned 300 total points
ID: 9795522
Try this:
This will split your path to components (directories) separated by "\"

----------------------------------
Private Sub Dir1_Change()
   Dim vArray
   Dim i As Integer

   vArray = Split(Dir1.Path, "\")
   For i = 0 To UBound(vArray)
         MsgBox vArray(i)
   Next i
End Sub
---------------------------------

If you need only the last component:

--------------------------------
Private Sub Dir1_Change()

Dim vArray
Dim i As Integer

vArray = Split(Dir1.Path, "\")

    MsgBox vArray(UBound(vArray))
   
End Sub
----------------------------------
0
 

Expert Comment

by:vbhelp12345
ID: 9795537
here is it is

Dim dir1 As String

Private Sub Command1_Click()
Dim i As Integer
Dim lent As Integer
Dim j As Integer
Dim varname As String
lent = Len(dir1)
i = 1
Do While i < lent
If Mid(dir1, i, 1) = "\" Then
  j = i
End If
i = i + 1
Loop
varname = Mid(dir1, j + 1, (lent - j) - 1)
MsgBox varname
End Sub

Private Sub Form_Load()
dir1 = "C:\Documents and settings\all users\Desktop\"
0
 

Author Comment

by:Shibjuh
ID: 9795570
Thanks guys :) very fast replies. Sorry vbhelp12345 for not giving you points but dbrckovi's answer was shorter
0
 
LVL 11

Expert Comment

by:dbrckovi
ID: 9795584
Thanx!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

650 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