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
' in place of the above..you could use the follwing to add the data to a
table:
' lets add the results to a table
dim rstRecs as dao.recordset
set rstRecs = currentdb.OpenRecordSet("tblDirs")
For i = 1 To dlist.Count
rstRecs.AddNew
rstRecs!FileName = dlist(i)
rstRecs!????Date = filedateTime(dlist(i))
rstRecs.Update
next i
rstRecs.Close
set rstRecs = nothing
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
pleaseNOO...@msn.com
http://www.attcanada.net/~kallal.msn
I know I shouldn't expect you to write this code for me; if I wasn't such a newbie at this, I wouldn't be on this Newsgroup.
Gotta start somewhere <gr>!
Thanks,
Len
I managed to get around the DB issues I was having, just took a little looking into. I do however have an interesting thing happening...
after insertng six records into the recordset, the code blows up with "The field is to small to accept the amount of data you attempted to add. Try inserting or pasting less data." The data is fairly consistent in size. Any thoughts?
Thanks, Len
on error resume next <----------
strTemp = Dir(startDir)
Do While strTemp <> ""
dlist.Add startDir & strTemp
strTemp = Dir
Loop
That is cheap solution...but it should work!
Also, you should note that this program technique of a program calling its
self over and over is that we call recursion. Recursion is rather very cool
code solution to many types of computer problems. Recursion (having code
call and re-use its self) can save a LOT of code, and can solve some really
cool things.
As for your other questions...I assume you figured out to add the dao 3.6
reference to my example for the reocrdset code?
While in code..use tools->references-> add the Microsoft 3.6 dao library
ref.
>The field is to small to accept the amount of data you attempted to add.
Try inserting or pasting less data." The data is fairly consistent in size.
The default field size in a table is only 50 characters. You go quite far
into the directory tree..that result will be longer then 50 chars. You will
need to increase the field size in the table design mode..
>Also, you should note that this program technique of a program calling its
>self over and over is that we call recursion.
From the Programmer's Dictionary:
Recursion, n. See: Recursion.
John W. Vinson[MVP]
Come for live chats every Tuesday and Thursday
http://go.compuserve.com/msdevapps?loc=us&access=public
' now process each folder (recursion)
For Each varFolderName In colFolders
If (GetAttr(strStartDir + varFolderName) And vbDirectory) = vbDirectory Then
Call FillDir(strStartDir & varFolderName & "\", colDirList)
End If
Next varFolderName
Thanks,
Bud
Sub dirTest()
to
Sub dirTest(startDir As String)
and remove the line
startDir = "C:\access\"
from the body of the code.
To invoke a browser to retrieve the folder name, take a look at
http://www.mvps.org/access/api/api0002.htm at "The Access Web"
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(No private e-mails, please)
"Bud T" <Bu...@discussions.microsoft.com> wrote in message
news:E1467837-EB09-46B8...@microsoft.com...