472,123 Members | 1,334 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,123 software developers and data experts.

Storing directory names in a table

I am hoping someone here has experience with this. I am using Access
97, but if someone has done this in another version I'd appreciate
input as well

I need to populate a table with subdirectory names.

Example:
c:\Tests has the subdirectories test1, test2 and test3. Each directory
has a file called test1.txt, test2.txt, test3.txt. I would like to
populate a table with just the subdirectory names.

I hope this was clear enough, and I realy hope someone has come across
this before.

Thanks in advance,
Sheila
Nov 13 '05 #1
2 1756
Do you want JUST the directory names, or how about something that results
all file names in he dir, and (also, all those below?).

Would that help?

Here is some test code that takes a given directory, and retunes ALL files
(and includes all files in the sub-dirs also).
Sub dirTest()

Dim dlist As New Collection
Dim startDir As String
Dim i As Integer

startDir = "C:\access\"
Call FillDir(startDir, dlist)

MsgBox "there are " & dlist.Count & " in the dir"

' lets printout the stuff into debug window for a test

For i = 1 To dlist.Count
Debug.Print dlist(i)
Next i

End Sub
Sub FillDir(startDir As String, dlist As Collection)

' build up a list of files, and then
' add add to this list, any additinal
' folders

Dim strTemp As String
Dim colFolders As New Collection
Dim vFolderName As Variant

strTemp = Dir(startDir)

Do While strTemp <> ""
dlist.Add startDir & strTemp
strTemp = Dir
Loop

' now build a list of additional folders
strTemp = Dir(startDir & "*.", vbDirectory)

Do While strTemp <> ""
If (strTemp <> ".") And (strTemp <> "..") Then
colFolders.Add strTemp
End If
strTemp = Dir
Loop

' now process each folder (recursion)
For Each vFolderName In colFolders
Call FillDir(startDir & vFolderName & "\", dlist)
Next vFolderName

End Sub

--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl*****************@msn.com
http://www.attcanada.net/~kallal.msn
Nov 13 '05 #2
The following will give you all of the subdirectories:

Sub ListSubdirectories()
Dim strFolder As String

strFolder = Dir$("C:\Tests\", vbDirectory)
Do While Len(strFolder) > 0
If strFolder <> "." And strFolder <> ".." Then
If (GetAttr("C:\Tests\" & strFolder) And vbDirectory) =
vbDirectory Then
Debug.Print strFolder
End If
End If
strFolder = Dir$()
Loop

End Sub

Hopefully that's enough to get you going.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(No private e-mails, please)
"Sheila" <sh********@shaw.ca> wrote in message
news:e3**************************@posting.google.c om...
I am hoping someone here has experience with this. I am using Access
97, but if someone has done this in another version I'd appreciate
input as well

I need to populate a table with subdirectory names.

Example:
c:\Tests has the subdirectories test1, test2 and test3. Each directory
has a file called test1.txt, test2.txt, test3.txt. I would like to
populate a table with just the subdirectory names.

I hope this was clear enough, and I realy hope someone has come across
this before.

Thanks in advance,
Sheila

Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by dave | last post: by
9 posts views Thread by pescott | last post: by
3 posts views Thread by hamvil79 | last post: by
6 posts views Thread by Kieran Benton | last post: by
1 post views Thread by tangus via DotNetMonster.com | last post: by
4 posts views Thread by IkBenHet | last post: by
10 posts views Thread by deciacco | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.