Solved

Just the dir name not the whole path

Posted on 2003-11-21
4
265 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
  • 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

821 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