Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Dossier vide

24 réponses
Avatar
Alf
Bonjour =C3=A0 tous,

Comment tester en vba si un dossier est vide ?
Vide de sous-dossiers et vide de fichiers...


Merci de votre aide =C3=A0 tous
Alf

4 réponses

1 2 3
Avatar
Michd
https://www.excelguru.ca/content.php?140
'-------------------------------------------------------------------
Private Function CountFiles(strDirectory As String, Optional strExt As
String = "*.*") As Double
'Author : Ken Puls (www.excelguru.ca)
'Function purpose: To count files in a directory. If a file extension is
provided,
' then count only files of that type, otherwise return a count of all
files.
Dim objFso As Object
Dim objFiles As Object
Dim objFile As Object
'Set Error Handling
On Error GoTo EarlyExit
'Create objects to get a count of files in the directory
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objFiles = objFso.GetFolder(strDirectory).Files
'Count files (that match the extension if provided)
If strExt = "*.*" Then
CountFiles = objFiles.Count
Else
For Each objFile In objFiles
If UCase(Right(objFile.Path, (Len(objFile.Path) -
InStrRev(objFile.Path, ".")))) = UCase(strExt) Then
CountFiles = CountFiles + 1
End If
Next objFile
End If
EarlyExit:
'Clean up
On Error Resume Next
Set objFile = Nothing
Set objFiles = Nothing
Set objFso = Nothing
On Error GoTo 0
End Function
'----------------------------------------------------------------
MichD
Avatar
Jacky
Merci Denis
Comme dit un peu plus dans ce file
En supprimant le sous-dossier puis le recréer, cela fonctionne
J'avais par curiosité listé ce sous-dossier et il a trouvé un fichier
qui n'était absolument pas dans ce dossier,
Je l'ai supprimer, puis re-listé, il en a trouvé un autre qui lui non
plus n'était pas dans ce dossier
Alors j'ai fini par supprimer le dossier et là ...cela fonctionne.
Cela reste un mystère pour moi.
Salutations
JJ
Michd a exposé le 11/12/2017 :
https://www.excelguru.ca/content.php?140
'-------------------------------------------------------------------
Private Function CountFiles(strDirectory As String, Optional strExt As String
= "*.*") As Double
'Author : Ken Puls (www.excelguru.ca)
'Function purpose: To count files in a directory. If a file extension is
provided,
' then count only files of that type, otherwise return a count of all
files.
Dim objFso As Object
Dim objFiles As Object
Dim objFile As Object
'Set Error Handling
On Error GoTo EarlyExit
'Create objects to get a count of files in the directory
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objFiles = objFso.GetFolder(strDirectory).Files
'Count files (that match the extension if provided)
If strExt = "*.*" Then
CountFiles = objFiles.Count
Else
For Each objFile In objFiles
If UCase(Right(objFile.Path, (Len(objFile.Path) -
InStrRev(objFile.Path, ".")))) = UCase(strExt) Then
CountFiles = CountFiles + 1
End If
Next objFile
End If
EarlyExit:
'Clean up
On Error Resume Next
Set objFile = Nothing
Set objFiles = Nothing
Set objFso = Nothing
On Error GoTo 0
End Function
'----------------------------------------------------------------
MichD
Avatar
JièL
Hello,
de temps en temps il se "cré" un fichier thumbqqchose qui est masqué par
défaut, c'est les miniatures des images qui pourraient/pouvaient être
dans ce dossier.
--
JièL 1 vis zible
Le 11/12/2017 à 16:51, Jacky a écrit :
Merci Denis
Comme dit un peu plus dans ce file
En supprimant le sous-dossier puis le recréer, cela fonctionne
J'avais par curiosité listé ce sous-dossier et il a trouvé un fichier
qui n'était absolument pas dans ce dossier,
Je l'ai supprimer, puis re-listé, il en a trouvé un autre qui lui non
plus n'était pas dans ce dossier
Alors j'ai fini par supprimer le dossier et là ...cela fonctionne.
Cela reste un mystère pour moi.
Salutations
JJ
Michd a exposé le 11/12/2017 :
https://www.excelguru.ca/content.php?140
'-------------------------------------------------------------------
Private Function CountFiles(strDirectory As String, Optional strExt As
String = "*.*") As Double
'Author          : Ken Puls (www.excelguru.ca)
'Function purpose: To count files in a directory.  If a file extension
is provided,
'   then count only files of that type, otherwise return a count of
all files.
    Dim objFso As Object
    Dim objFiles As Object
    Dim objFile As Object
    'Set Error Handling
    On Error GoTo EarlyExit
    'Create objects to get a count of files in the directory
    Set objFso = CreateObject("Scripting.FileSystemObject")
    Set objFiles = objFso.GetFolder(strDirectory).Files
    'Count files (that match the extension if provided)
    If strExt = "*.*" Then
        CountFiles = objFiles.Count
    Else
        For Each objFile In objFiles
            If UCase(Right(objFile.Path, (Len(objFile.Path) -
InStrRev(objFile.Path, ".")))) = UCase(strExt) Then
                CountFiles = CountFiles + 1
            End If
        Next objFile
    End If
EarlyExit:
    'Clean up
    On Error Resume Next
    Set objFile = Nothing
    Set objFiles = Nothing
    Set objFso = Nothing
    On Error GoTo 0
End Function
'----------------------------------------------------------------
MichD
Avatar
Jacky
Hello Jièl
Ce n'était pas mon cas,
Il a trouvé à chaque fois un fichier (et un seul) existant situé dans
un autre répertoire
Après suppression, il en trouve un autre, et ainsi de suite, jusqu'à
suppression du dossier.
Je n'avais jamais vue cela.
Comme dit c'est et restera un mystère
Salutations
JJ
JièL a exposé le 11/12/2017 :
Hello,
de temps en temps il se "cré" un fichier thumbqqchose qui est masqué par
défaut, c'est les miniatures des images qui pourraient/pouvaient être dans ce
dossier.
--
JièL 1 vis zible
1 2 3