File system access

W

woody

I've been familiar with Visual Basic tools since Version 3.0, and also
VBA used with Microsoft Access since Access 2.0.

I mostly have worked with asp/database coding, but recently I started
on a project using Access as a rich client.

I know it is quite simple these days to use the FileSystemObject to
get to the Windows file system directories and files, but I was
wondering if anyone out there knows what life was like before the
Windows Scripting Host and the FileSystemObject?

Was there a way to get to the file system in Access 2.0
through Access 95? What about Access 97?

I know the filesystem class was available in the VBA classes, but that
doesn't have any methods that return collections of files or
directories as subdirectories and what not.

Back then, was it possible to get a list box populated with the file
names in a directory on the disk?

Just wondering.
 
D

Douglas J. Steele

The Dir function lets you list all of the files in a directory. You can also
use API calls (FindFirstFile, FindNextFile)

Personally, I always avoid using WSH and FSO in Access. It's prone to
versioning problems, and it adds a fair bit of unnecessary overhead.
 
A

Albert D. Kallal

I wrote a recursive piece of code that loads up a collection for a97. So, if
you pass it a dir, it returns a list of files, and all sub-folders.

here is the code:

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top