Code qui plante le Dir$
- Code : Tout sélectionner
Sub Initialize
filelevel1$ = Dir$("C:\", ATTR_DIRECTORY)
While (filelevel1$ <> "")
If Instr(1, filelevel1$,".")=0 Then Call sub1(filelevel1$)
' The line below triggers the error "Illegal Function Call"
filelevel1$ = Dir$()
Wend
End Sub
Sub sub1(level1 As Variant)
If Instr(1, level1,".")=0 Then filelevel2$ = Dir$("C:\"+level1+"\*.*")
While (filelevel2$ <> "")
' Perform desired operation on file in sub-directory
' Below accesses next file in sub-directory
filelevel2$=Dir()
Wend
End Sub
- Code : Tout sélectionner
Sub Initialize
Dim filelist() As String
count=0
Filelevel1$ = Dir$("C:\", ATTR_DIRECTORY)
While (filelevel1$ <> "")
Redim Preserve Filelist(count)
Filelist(count) = Filelevel1$
count = count + 1
Filelevel1$=Dir$()
Wend
For i = 0 To count-1
filelevel1$ = Filelist(i)
If Instr(1, filelevel1$,".")=0 Then
' We have a sub-dir:
Call sub1(filelevel1$)
Else
'We have a file. Perform desired check or operation
End If
Next
End Sub
Sub sub1(level1 As Variant)
If Instr(1, level1,".")=0 Then filelevel2$ = Dir$("C:\"+level1+"\*.*")
While (filelevel2$ <> "")
' Perform desired operation on file in sub-directory
' Below accesses next file in sub-directory
filelevel2$=Dir()
Wend
End Sub