I needed a program to loop through all sub-folders of a specified directory and check if a file exists. For testing, I made the folder to loop through c:\ and then I stuck a file called findme.txt in one of the sub-folders. I added code to show all sub-folders in c:\. This worked fine. I then used the DIR function to see if the file existed in any of the sub-folders. As soon as this command is added, I get an error "Invalid procedure call" and it highlights "A = Dir$". If I run the DIR command separately, it works fine. If I run the code to enumerate the sub-folders, it works fine, but combined always gives an error. What am I doing wrong? The code below works, until you uncomment out the Dir function code.
Dim A As String
A = Dir$("C:\", vbDirectory)
Do While A <> "" And A <> "." And A <> ".." And A <> "live"
If GetAttr("c:\" & A) = "16" Or GetAttr("c:\" & A) = "17" Then
MsgBox "c:\" & A
'If Dir("c:\" & A & "\findme.txt") <> "" Then
'Form1.List1.AddItem "c:\" & A & "\findme.txt"
'Form1.List1.AddItem "c:\" & A
A = Dir$