Re: Calling an MS-DOS command
- From: Alan Searle <aj_searle@xxxxxxxxxxxx>
- Date: Thu, 02 Mar 2006 17:51:53 +0100
Hi Albert,
Thanks very much for this. I'll give it a try and, indeed, it may be better to use your code than to call DOS commands. I'll weigh up the pros and cons.
Regards,
Alan.
Albert D. Kallal schrieb:
.Yes, I have been using dir() but want to retrieve a whole directory tree and have found that there is a rather neat MS-DOS one-liner that will do all the leg-work for me. This is ...
Well, you can use dir..and some recusrion to traverse the tree....
Here is my code...
The first sub shows how to use the routine....
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
- Prev by Date: Re: delete report fields if no data
- Next by Date: Attaching SQL Table w/o DSN
- Previous by thread: delete report fields if no data
- Next by thread: Attaching SQL Table w/o DSN
- Index(es):
Relevant Pages
|