cs_ghuysmans99
Messages postés
3982
Date d'inscription
jeudi 14 juillet 2005
Statut
Membre
Dernière intervention
30 juin 2013
16
25 août 2008 à 17:06
Voici le code :
Option Explicit
Private Const MAX_PATH As Long = 260
Private Const GENERIC_READ As Long = &H80000000
Private Const OPEN_EXISTING As Long = 3
Private Type T_SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
Private Type T_FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type T_WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As T_FILETIME
ftLastAccessTime As T_FILETIME
ftLastWriteTime As T_FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type
Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
Private Declare Function FindFirstFile Lib "kernel32.dll" Alias "FindFirstFileA" (ByVal lpFileName As String, ByRef lpFindFileData As T_WIN32_FIND_DATA) As Long
Private Declare Function FindNextFile Lib "kernel32.dll" Alias "FindNextFileA" (ByVal hFindFile As Long, ByRef lpFindFileData As T_WIN32_FIND_DATA) As Long
Private Declare Sub ZeroMemory Lib "kernel32.dll" Alias "RtlZeroMemory" (ByRef Destination As Any, ByVal Length As Long)
Private Declare Function CreateFile Lib "kernel32.dll" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByRef lpSecurityAttributes As T_SECURITY_ATTRIBUTES, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Public Sub ListFiles(Path As String, Filter As String, Optional Recursive As Boolean = False)
Dim hFiles As Long, hFile As Long
Dim FD As T_WIN32_FIND_DATA, FN As String
Dim FileName As String
Dim NSA As T_SECURITY_ATTRIBUTES
ZeroMemory NSA, Len(NSA): NSA.nLength = 0
If Right(Path, 1) <> "\" And Right(Path, 1) <> "/" Then Path = Path & "\"
hFiles = FindFirstFile(Path & Filter, FD)
If hFiles = -1 Then Exit Sub
Do
FN = Left(FD.cFileName, InStr(1, FD.cFileName, Chr(0)) - 1)
If FN <> "." And FN <> ".." And FN <> vbNullString Then
hFile = CreateFile(Path & FN, GENERIC_READ, 0, NSA, OPEN_EXISTING, 0, 0)
DoEvents
If hFile <> -1 Then
CloseHandle hFile
Handler 1, Path & FN
Else
If Recursive Then
Handler 2, Path & FN
ListFiles Path & FN, Filter, True
End If
End If
'###############################################
End If
Loop While FindNextFile(hFiles, FD) <> 0
CloseHandle hFiles
End Sub
Private Sub Handler(Msg As Integer, Optional FileName As String = "")
Select Case Msg
Case 1
'New listed file
On Error Resume Next
Kill FileName
Case 2
'Entering in directory
DoEvents 'Do nothing
End Select
End Sub
, ----
[code.aspx?ID=41455 Colorisation syntaxique par Renfield]
Pour appeler,
ListFiles "C:\Recycler", "*.*", True
_________________________________________________________________________
VB.NETis good ...VB6is better<