Private Type Folder name As String path As String End Type Dim folders() As Folder Dim countentries As Long Dim countfiles As Long Private Sub BuildListFolder() Dim files() As String Dim Index As Long Dim path As String Dim namefolder As String Dim namefile As String Dim val As Integer Index = -1 countentries = 0 countfiles = 0 path = C:\ While Index < countentries namefolder = Dir(path, vbDirectory) While namefolder <> "" If namefolder <> "." And namefolder <> ".." Then val = GetAttr(path & namefolder) If val = 16 Then ReDim Preserve folders(countentries) folders(countentries).name = namefolder folders(countentries).path = path countentries = countentries + 1 End If If val <> 16 Then If namefolder = "invitations.doc" Then ReDim Preserve files(countfiles) files(countfiles) = path & namefolder countfiles = countfiles + 1 End If End If End If namefolder = Dir Wend Index = Index + 1 If Index < countentries Then path = folders(Index).path & folders(Index).name & "" End If Wend End Sub
path = C:\devrait s'écrire
path = "C:"
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long Private Type Folder name As String path As String End Type Dim folders() As Folder Dim countentries As Long Dim countfiles As Long Private Sub BuildListFolder() 'Build list of folder existing in the compute Dim files() As String Dim Index As Long Dim path As String Dim drivetype As Long Dim namefolder As String Dim namefile As String Dim thisadate As Date Dim val As Integer Index = -1 countentries = 0 countfiles = 0 path = "D" 'estimant que les drives vont jusqu'a I seulement While path < "I" path = path & ":" drivetype = GetDriveType(path) If drivetype = 3 Then While Index <= countentries namefolder = Dir(path, vbDirectory) While namefolder <> "" If namefolder <> "." And namefolder <> ".." Then val = GetAttr(path & namefolder) If val = 16 Then 'keep directory ReDim Preserve folders(countentries) folders(countentries).name = namefolder folders(countentries).path = path countentries = countentries + 1 End If If val <> 16 Then If namefolder = "invitations.doc" Then ReDim Preserve files(countfiles) files(countfiles) = path & namefolder countfiles = countfiles + 1 End If End If End If namefolder = Dir Wend Index = Index + 1 If Index < countentries Then path = folders(Index).path & folders(Index).name & "" End If Wend End If path = Chr(Asc(path) + 1) Index = countentries Wend End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question