timadone
Messages postés3Date d'inscriptionmercredi 16 mai 2007StatutMembreDernière intervention13 septembre 2010
-
9 sept. 2010 à 17:05
timadone
Messages postés3Date d'inscriptionmercredi 16 mai 2007StatutMembreDernière intervention13 septembre 2010
-
13 sept. 2010 à 13:13
En utilisant le code ci dessous par exemple, comment peut on compter le nombre de fichiers dans un dossiers et déclencher une alerte ( fenêtre ou mail ou bip sonore) uniquement quand le nombre de fichiers dépasse 10 fichiers par exemple?
Dim Path
Path = "D:\Mes scripts vbs"
MsgBox ShowFolderList(Path),vbmessage,"Fichiers contenus dans le répertoire " & Path
Function ShowFolderList(strPath)
Dim fso, Dossiers, fic, fichiers, strListe, nbre
Set fso = CreateObject("Scripting.FileSystemObject")
Set Dossiers = fso.GetFolder(strPath)
Set fic = Dossiers.Files
'pour chaque fichier de mon objet files de mon objet fso...:)
For Each fichiers in fic
'le nom du fichier
nbre = nbre + 1
'strListe = strListe & vbcrlf & vbcrlf & fichiers.Name & " Date (jjmmaa) : " & fichiers.DateLastModified & " Taille (octet) : " & fichiers.Size
Next
ShowFolderList = nbre
'ShowFolderList = strListe
End Function
Set fso = Nothing
A voir également:
Compter le nombre de fichier dans un dossier python
the_little_big_man
Messages postés86Date d'inscriptionlundi 22 janvier 2007StatutMembreDernière intervention14 février 2011 10 sept. 2010 à 10:58
Sub fichier()
Dim Path
Path = "C:\Documents and Settings\robert mugabuhamye\Desktop"
Dim nbfich As Integer
nbfich = ShowFolderList(Path) 'tu recupère le nombre de fichier
MsgBox nbfich, vbOKOnly, "Fichiers contenus dans le répertoire " & Path 'tu l'affiche
If nbfich > 10 Then 'si supérieur à 10
MsgBox "Attention le nombre de fichiers est > à 10", vbExclamation + vbOKOnly, "Alerte" 'tu le signale
End If
End Sub
Function ShowFolderList(strPath) As Integer
Dim fso, Dossiers, fic, fichiers, strListe, nbre
Set fso = CreateObject("Scripting.FileSystemObject")
Set Dossiers = fso.GetFolder(strPath)
Set fic = Dossiers.Files
'pour chaque fichier de mon objet files de mon objet fso...:)
For Each fichiers In fic
'le nom du fichier
nbre = nbre + 1
'strListe = strListe & vbcrlf & vbcrlf & fichiers.Name & " Date (jjmmaa) : " & fichiers.DateLastModified & " Taille (octet) : " & fichiers.Size
Next
ShowFolderList = nbre
'ShowFolderList = strListe
Set fso = Nothing
End Function
A good excercise for the Heart is to bend down and help another up...
cs_JMO
Messages postés1854Date d'inscriptionjeudi 23 mai 2002StatutMembreDernière intervention24 juin 201827 12 sept. 2010 à 17:09
Bonjour,
Pourquoi ne pas utiliser la propriété count
Option Explicit
Const MyFolder = "d:\RECUP"
Dim objFso
Set objFso = CreateObject("Scripting.FileSystemObject")
If objFso.FolderExists(MyFolder) Then
If objFso.GetFolder(MyFolder).Files.Count > 10 Then MsgBox "alert",vbExclamation
End If
Set objFso = Nothing