by BuBa_kInG (6 Submissions)
Category: Files/File Controls/Input/Output
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Mon 22nd May 2000
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Finding files
Sub listadriv()
Set fso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Dim d, dc, s
Set dc = fso.Drives
For Each d In dc
If d.DriveType = 2 Or d.DriveType = 3 Then
Call FindSubFolders(d.Path & "\") 'Find Folders in Drive
End If
Next
End Sub
Sub FindSubFolders(folderspec)
Set fso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Dim f, f1, sf
Set f = fso.GetFolder(folderspec)
Set sf = f.SubFolders 'Find sub folders
For Each f1 In sf
Text2 = f1.Path
DoEvents
Call FindFiles(f1.Path) 'find files in dir
Call FindSubFolders(f1.Path) 'Recall to get the sub folders :=)
Next
End Sub
Sub FindFiles(folderspec)
Dim fso, fc, f1, file1, f, s
Set fso = CreateObject("Scripting.FileSystemObject")
file1 = "Notepad.exe" ' file to find
Set f = fso.GetFolder(folderspec)
Set fc = f.Files
For Each f1 In fc
s = fso.getfilename(f1.Path)
DoEvents ' give the comp a break
If s = file1 Then
Text3 = "File found!!! in " & f1.Path
End If
Next
End Sub
Private Sub Command1_Click()
Call listadriv
End Sub