OVH Cloud OVH Cloud

ou est la faute svp ?

3 réponses
Avatar
Bismark Prods
Public Function GetNumFiles(ByVal Path As String) As Long
Dim FichierCourant As String
Dim Resultat As Long

Resultat = 0
If Path = "" Then
GetNumFiles = 0
Exit Function
End If

If Right$(Path, 1) <> "\" Then
Path = Path & "\"
End If

FichierCourant = Dir$(Path, vbDirectory)

Do Until FichierCourant = ""
DoEvents
If FichierCourant <> "." And FichierCourant <> ".." Then
Debug.Print FichierCourant
If GetAttr(Path & FichierCourant) = vbDirectory And vbDirectory Then
Resultat = Resultat & GetNumFiles(Path & FichierCourant & "\")
Else
Resultat = Resultat + 1
End If
End If
FichierCourant = Dir$
Loop

GetNumFiles = Resultat

End Function

Cette fonction doit me renvoyer par recursivité le nombre d'éléments contenu
dans un répertoire et sous répertoire, mais cela bug et je ne suis pas sur
de ce qui est faux `?

merci

3 réponses

Avatar
ng
ou dans ce cas tu peux utiliser un FileListBox...
"François Picalausa" a écrit dans le message de news:

Bonjour/soir,

Deux erreurs:
Une erreur de And:
GetAttr(Path & FichierCourant) = vbDirectory And vbDirectory
Il s'agit de
(GetAttr(Path & FichierCourant) And vbDirectory) = vbDirectory

Sinon, Dir vide son buffer à chauqe fois qu'on l'apelle.
Donc, pas question d'implémenter une récursivité directe.

Une solution est présentée dans le KB pour palier à ce problème:
http://support.microsoft.com/default.aspx?kbid5476

--
François Picalausa (MVP VB)
FAQ VB : http://faq.vb.free.fr
MSDN : http://msdn.microsoft.com


"Bismark Prods" a écrit dans le message de
news:
> Public Function GetNumFiles(ByVal Path As String) As Long
> Dim FichierCourant As String
> Dim Resultat As Long
>
> Resultat = 0
> If Path = "" Then
> GetNumFiles = 0
> Exit Function
> End If
>
> If Right$(Path, 1) <> "" Then
> Path = Path & ""
> End If
>
> FichierCourant = Dir$(Path, vbDirectory)
>
> Do Until FichierCourant = ""
> DoEvents
> If FichierCourant <> "." And FichierCourant <> ".." Then
> Debug.Print FichierCourant
> If GetAttr(Path & FichierCourant) = vbDirectory And vbDirectory
> Then Resultat = Resultat & GetNumFiles(Path & FichierCourant
> & "") Else
> Resultat = Resultat + 1
> End If
> End If
> FichierCourant = Dir$
> Loop
>
> GetNumFiles = Resultat
>
> End Function
>
> Cette fonction doit me renvoyer par recursivité le nombre d'éléments
> contenu dans un répertoire et sous répertoire, mais cela bug et je ne
> suis pas sur de ce qui est faux `?
>
> merci




Avatar
François Picalausa
Bonjour/soir,

AMHA, il est inutile d'employer un filelistbox qui alourdirait le code et
forcerait le développeur à utiliser une feuille....
Autant que le code soit flexible au maximum et jeter un oeil à la fiche de
la KB ;-)

--
François Picalausa (MVP VB)
FAQ VB : http://faq.vb.free.fr
MSDN : http://msdn.microsoft.com


"ng" a écrit dans le message de
news:OG$
ou dans ce cas tu peux utiliser un FileListBox...
"François Picalausa" a écrit dans le message de
news:
Bonjour/soir,

Deux erreurs:
Une erreur de And:
GetAttr(Path & FichierCourant) = vbDirectory And vbDirectory
Il s'agit de
(GetAttr(Path & FichierCourant) And vbDirectory) = vbDirectory

Sinon, Dir vide son buffer à chauqe fois qu'on l'apelle.
Donc, pas question d'implémenter une récursivité directe.

Une solution est présentée dans le KB pour palier à ce problème:
http://support.microsoft.com/default.aspx?kbid5476

--
François Picalausa (MVP VB)
FAQ VB : http://faq.vb.free.fr
MSDN : http://msdn.microsoft.com


"Bismark Prods" a écrit dans le message de
news:
Public Function GetNumFiles(ByVal Path As String) As Long
Dim FichierCourant As String
Dim Resultat As Long

Resultat = 0
If Path = "" Then
GetNumFiles = 0
Exit Function
End If

If Right$(Path, 1) <> "" Then
Path = Path & ""
End If

FichierCourant = Dir$(Path, vbDirectory)

Do Until FichierCourant = ""
DoEvents
If FichierCourant <> "." And FichierCourant <> ".." Then
Debug.Print FichierCourant
If GetAttr(Path & FichierCourant) = vbDirectory And vbDirectory
Then Resultat = Resultat & GetNumFiles(Path & FichierCourant
& "") Else
Resultat = Resultat + 1
End If
End If
FichierCourant = Dir$
Loop

GetNumFiles = Resultat

End Function

Cette fonction doit me renvoyer par recursivité le nombre d'éléments
contenu dans un répertoire et sous répertoire, mais cela bug et je
ne suis pas sur de ce qui est faux `?

merci






Avatar
Bismark Prods
je te remercie francois je ne sais pas encore si c'est exactement ca dont
j'ai besoin ! Mais tu as parfaitement répondu à mes attentes. Bonne soirée

"François Picalausa" a écrit dans le message de
news:%
Bonjour/soir,

AMHA, il est inutile d'employer un filelistbox qui alourdirait le code et
forcerait le développeur à utiliser une feuille....
Autant que le code soit flexible au maximum et jeter un oeil à la fiche de
la KB ;-)

--
François Picalausa (MVP VB)
FAQ VB : http://faq.vb.free.fr
MSDN : http://msdn.microsoft.com


"ng" a écrit dans le message de
news:OG$
> ou dans ce cas tu peux utiliser un FileListBox...
> "François Picalausa" a écrit dans le message de
> news:
>> Bonjour/soir,
>>
>> Deux erreurs:
>> Une erreur de And:
>> GetAttr(Path & FichierCourant) = vbDirectory And vbDirectory
>> Il s'agit de
>> (GetAttr(Path & FichierCourant) And vbDirectory) = vbDirectory
>>
>> Sinon, Dir vide son buffer à chauqe fois qu'on l'apelle.
>> Donc, pas question d'implémenter une récursivité directe.
>>
>> Une solution est présentée dans le KB pour palier à ce problème:
>> http://support.microsoft.com/default.aspx?kbid5476
>>
>> --
>> François Picalausa (MVP VB)
>> FAQ VB : http://faq.vb.free.fr
>> MSDN : http://msdn.microsoft.com
>>
>>
>> "Bismark Prods" a écrit dans le message de
>> news:
>>> Public Function GetNumFiles(ByVal Path As String) As Long
>>> Dim FichierCourant As String
>>> Dim Resultat As Long
>>>
>>> Resultat = 0
>>> If Path = "" Then
>>> GetNumFiles = 0
>>> Exit Function
>>> End If
>>>
>>> If Right$(Path, 1) <> "" Then
>>> Path = Path & ""
>>> End If
>>>
>>> FichierCourant = Dir$(Path, vbDirectory)
>>>
>>> Do Until FichierCourant = ""
>>> DoEvents
>>> If FichierCourant <> "." And FichierCourant <> ".." Then
>>> Debug.Print FichierCourant
>>> If GetAttr(Path & FichierCourant) = vbDirectory And vbDirectory
>>> Then Resultat = Resultat & GetNumFiles(Path & FichierCourant
>>> & "") Else
>>> Resultat = Resultat + 1
>>> End If
>>> End If
>>> FichierCourant = Dir$
>>> Loop
>>>
>>> GetNumFiles = Resultat
>>>
>>> End Function
>>>
>>> Cette fonction doit me renvoyer par recursivité le nombre d'éléments
>>> contenu dans un répertoire et sous répertoire, mais cela bug et je
>>> ne suis pas sur de ce qui est faux `?
>>>
>>> merci