PC Review


Reply
Thread Tools Rate Thread

How can I access Directory Names?

 
 
Mac Lingo
Guest
Posts: n/a
 
      17th Sep 2007
I need to be able to get at Directory Names. The3 problem is that I want to
go thru my directories with a VBA program and would like, for instance, to
change directories within that program.

I know how to use "Dir" to get File Names, but it doesn't seem to display
Directory names.

Anyone know how?

Thanks,
Mac Lingo


 
Reply With Quote
 
 
 
 
Leith Ross
Guest
Posts: n/a
 
      17th Sep 2007
On Sep 16, 9:27 pm, "Mac Lingo" <M...@SV-CaliforniaGirl.Com> wrote:
> I need to be able to get at Directory Names. The3 problem is that I want to
> go thru my directories with a VBA program and would like, for instance, to
> change directories within that program.
>
> I know how to use "Dir" to get File Names, but it doesn't seem to display
> Directory names.
>
> Anyone know how?
>
> Thanks,
> Mac Lingo


Hello Mac,

Straight from the VBA help files. This will start with a parent
directory that you choose, and lists all other directories in that
folder.

' Display the names in C:\ that represent directories.
MyPath = "c:\" ' Set the path.
MyName = Dir(MyPath, vbDirectory) ' Retrieve the first entry.
Do While MyName <> "" ' Start the loop.
' Ignore the current directory and the encompassing directory.
If MyName <> "." And MyName <> ".." Then
' Use bitwise comparison to make sure MyName is a directory.
If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory
Then
Debug.Print MyName ' Display entry only if it
End If ' it represents a directory.
End If
MyName = Dir ' Get next entry.
Loop

Sincerely,
Leith Ross

 
Reply With Quote
 
=?Utf-8?B?T3NzaWVNYWM=?=
Guest
Posts: n/a
 
      17th Sep 2007
Hi Mac,

I modified this from the help files. It gets your current path and lists the
directories in that path.

Sub Test_Dir_Path()
Dim MyPath As String
Dim myName As String

' Display the names that represent directories.
MyPath = CurDir & "\" ' Set the path and add "\"

MsgBox "Current path is:- " & Chr(13) & _
MyPath 'For testing purposes

' Retrieve the first entry.
myName = Dir(MyPath, vbDirectory)
Do While myName <> "" ' Start the loop.
' Ignore the current and encompassing directory.
If myName <> "." And myName <> ".." Then
' Test that is a directory
If (GetAttr(MyPath & myName) And vbDirectory) _
= vbDirectory Then
MsgBox myName 'For testing purposes
End If
End If
myName = Dir 'Get next entry.
Loop
End Sub

Regards,

OssieMac



"Mac Lingo" wrote:

> I need to be able to get at Directory Names. The3 problem is that I want to
> go thru my directories with a VBA program and would like, for instance, to
> change directories within that program.
>
> I know how to use "Dir" to get File Names, but it doesn't seem to display
> Directory names.
>
> Anyone know how?
>
> Thanks,
> Mac Lingo
>
>
>

 
Reply With Quote
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      17th Sep 2007
Here is one more.

You can use the scripting runtime. This article is primarily focused on
files, but if you go down to the scripting section, you will see the folders
object:

http://msdn2.microsoft.com/en-us/library/Aa201321(office.11).aspx

--
Regards,
Tom Ogilvy


"Mac Lingo" wrote:

> I need to be able to get at Directory Names. The3 problem is that I want to
> go thru my directories with a VBA program and would like, for instance, to
> change directories within that program.
>
> I know how to use "Dir" to get File Names, but it doesn't seem to display
> Directory names.
>
> Anyone know how?
>
> Thanks,
> Mac Lingo
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help to copy files names in a column from one directory to another directory VBA Paul B Microsoft Excel Programming 4 10th Nov 2008 01:54 AM
Help: copying directory share names whilst doing bulk directory/file duplication. Troy Microsoft Windows 2000 1 4th May 2005 11:15 AM
Creating a macro that lists directory names within a directory.... =?Utf-8?B?QW5keQ==?= Microsoft Excel Programming 4 28th Nov 2004 06:13 AM
How is Windows directory names and registry names case-insensitive? Elder Hyde Microsoft Dot NET Framework 6 18th Jan 2004 11:22 AM
document directory names no longer match names of user owners habiru Windows XP Security 1 15th Sep 2003 03:22 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:03 PM.