Solved

Just the dir name not the whole path

Posted on 2003-11-21
4
267 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 75 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

732 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