jmfmarques
Messages postés
7666
Date d'inscription
samedi 5 novembre 2005
Statut
Membre
Dernière intervention
22 août 2014
27
12 mai 2007 à 22:28
Bon ...
Le vin était bon à table ...
J'ai donc fait ceci, à la méthode "grosse artillerie"
Réclame un bouton de commande Commande1 et un listbox List1
Je laisse le soin à mortalino de modifier pour écxrire dans les cellules plut^pt que dans la Listbox
Const MAX_PATH = 260
Const MAXDWORD = &HFFFF
Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
Private Type FILETIME
DateInfX As Long
DateSupX As Long
End Type
Private Type WIN32_FIND_DATA
AttributsX As Long
CreationTimeX As FILETIME
LastAccessTimeX As FILETIME
LastWriteTimeX As FILETIME
TailleSupX As Long
TailleInfX As Long
Reserve0X As Long
Reserve1X As Long
nomficX As String * MAX_PATH '
AlterneX As String * 14
End Type
Private Type SHFILEOPSTRUCT
hwnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAborted As Boolean
hNameMaps As Long
sProgress As String
End Type
Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
Private Declare Function GetFileAttributes Lib "kernel32" Alias "GetFileAttributesA" (ByVal lpFileName As String) As Long
Private Declare Function SetFileAttributes Lib "kernel32" Alias "SetFileAttributesA" (ByVal lpFileName As String, ByVal dwFileAttributes As Long) As Long
Const REPATTR = &H10
Const ARCHIVEATTR = &H20
Const CACHEATTR = &H2
Const NORMALATTR = &H80
Const READONLYATTR = &H1
Const SYSTEMATTR = &H4
Const TEMPATTR = &H100
Private Sub listonsdonc_Click()
derep$ = "d:\monoutil" ' ici ton répertoire
filtre$ = ".avi" 'ici ton filtre
allonsy derep$, derep$, filtre$
DoEvents
End Sub
Public Function allonsy(chemin As String, chemin0 As String, filtre As String)
Dim SHFileOp As SHFILEOPSTRUCT
Dim NomFic As String, nomrep As String, repnoms() As String, nbrep As Integer
Dim I As Integer, cherchechemin As Long, combtrouv As Integer
Dim WFD As WIN32_FIND_DATA
If Right(chemin, 1) <> "" Then chemin = chemin & ""
If Right(chemin0, 1) <> "" Then chemin0 = chemin0 & "" nbrep 0: combtrouv True
ReDim repnoms(nbrep)
cherchechemin = FindFirstFile(chemin & "*", WFD)
If cherchechemin <> -1 Then
Do While combtrouv
nomrep = WFD.nomficX
If (InStr(nomrep, Chr(0)) > 0) Then nomrep = Left(nomrep, InStr(nomrep, Chr(0)) - 1)
If (nomrep <> ".") And (nomrep <> "..") Then
If GetFileAttributes(chemin & nomrep) And REPATTR Then repnoms(nbrep) nomrep: nbrep nbrep + 1
ReDim Preserve repnoms(nbrep)
End If
End If
combtrouv = FindNextFile(cherchechemin, WFD)
Loop
combtrouv = FindClose(cherchechemin)
End If
cherchechemin = FindFirstFile(chemin & "*", WFD)
combtrouv = True
If cherchechemin <> -1 Then
While combtrouv
NomFic = WFD.nomficX
If (InStr(NomFic, Chr(0)) > 0) Then NomFic = Left(NomFic, InStr(NomFic, Chr(0)) - 1)
If (NomFic <> ".") And (NomFic <> "..") Then
allonsy = allonsy + (WFD.TailleSupX * MAXDWORD) + WFD.TailleInfX
On Error Resume Next
If chemin <> "" Then
ssplit = InStr(chemin & NomFic, chemin0)
tou = Mid(chemin & NomFic, ssplit + Len(chemin0) - 1)
If GetFileAttributes(chemin & NomFic) And REPATTR Then 's'il s'agit d'un répertoire
On Error Resume Next
toto = &H0
If GetFileAttributes(chemin & NomFic) And CACHEATTR Then toto = toto Or CACHEATTR
If GetFileAttributes(chemin & NomFic) And READONLYATTR Then toto = toto Or READONLYATTR
If GetFileAttributes(chemin & NomFic) And SYSTEMATTR Then toto = toto Or SYSTEMATTR
If GetFileAttributes(chemin & NomFic) And ARCHIVEATTR Then toto = toto Or ARCHIVEATTR
SetFileAttributes torep & tou, toto
Err.Clear
Else
myattr = GetAttr(chemin & NomFic)
If Right(chemin & NomFic, Len(filtre)) = filtre Then
List1.AddItem chemin & NomFic ' c'est ici, Mortalino que tu dois faire intrervenir les cellules de VBA
List1.Refresh ' et la aussi, bien sur
End If
End If
End If
Err.Clear
End If
combtrouv = FindNextFile(cherchechemin, WFD)
Wend
combtrouv = FindClose(cherchechemin)
End If
If nbrep > 0 Then
For I = 0 To nbrep - 1
allonsy = allonsy & allonsy(chemin & repnoms(I) & "", chemin0, filtre)
Next I
End If
End Function
Désolé de déballer toute cette artillerie (je vaus m'attacher( cette semaine à faire la même chose mais sans API)....
Sésolé également d'être si lourd, mais le vin me joue des tours, apparemment... et les yeux papillotent un peu...
Mais tout marche bien (testé).
.