directorie scannen

Status
Niet open voor verdere reacties.

jvsoest

Gebruiker
Lid geworden
2 okt 2000
Berichten
741
Hoi,

Alvorens zelf te gaan programmeren:


Ik zoek VB 6 code waarmee een complete directorie gescand word, inclusief subdirs en daarin alle subdirs enz.

In een array moet worden opgeslagen alle bestanden met padlokatie die tegen gekomen zijn.

Bedankt voor eventuele code of links!!
 
Met MS scripting runtime

'Eerst verwijzing zetten naar Microsoft scripting runtime '(Scrrun.dll)
'blnRecursive = true (subdirs meezoeken)
'blnRecursive = false (subdirs niet meezoeken)


Function GetFiles(strPath As String, _
dctDict As Dictionary, _
Optional blnRecursive As Boolean) As Boolean

Dim fsoSysObj As FileSystemObject
Dim fdrFolder As Folder
Dim fdrSubFolder As Folder
Dim filFile As File

Set fsoSysObj = New FileSystemObject

On Error Resume Next
Set fdrFolder = fsoSysObj.GetFolder(strPath)
If Err <> 0 Then
GetFiles = False
GoTo GetFiles_End
End If
On Error GoTo 0

For Each filFile In fdrFolder.Files
dctDict.Add filFile.Path, filFile.Path
Next filFile

If blnRecursive Then
For Each fdrSubFolder In fdrFolder.SubFolders
GetFiles fdrSubFolder.Path, dctDict, True
Next fdrSubFolder
End If

GetFiles = True

GetFiles_End:
Exit Function

End Function

Sub TestGetFiles()
Dim dctDict As Dictionary
Dim varItem As Variant

Set dctDict = New Dictionary
If GetFiles("C:\test", dctDict, True) Then
For Each varItem In dctDict
Debug.Print varItem
Next
End If
End Sub
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan