Option Explicit Const RootPath = "D:\SCRIPTS" Dim objFso Set objFso = CreateObject("Scripting.FileSystemObject") If objFso.FolderExists(RootPath) Then Call SearchFolders(objFso.GetFolder(RootPath)) End If Set objFso = Nothing Sub SearchFolders(ArgFolder) Dim subFolder MsgBox objFso.GetFolder(ArgFolder).Files.Count,,ArgFolder For Each subFolder In ArgFolder.SubFolders Call SearchFolders(subFolder) Next End Sub
Sub SearchFolders(ArgFolder) Dim subFolder MsgBox ArgFolder.Files.Count,,ArgFolder
'Const MyFolder = "C:\tmp" Dim MyFolder Dim oFSO,oFld Dim NbFile Dim Nombre Dim code_retour NbFile = 0 code_retour = 0 MyFolder = WScript.Arguments.Named("f") WScript.echo MyFolder Nombre = WScript.Arguments.Named("t") WScript.echo Nombre Set oFSO = CreateObject("Scripting.FileSystemObject") If not oFSO.FolderExists(MyFolder) Then WScript.echo "Le répertoire n'existe pas" Code_retour = 2 else NbFile = oFSO.GetFolder(MyFolder).Files.count For each oFld in oFSO.GetFolder(MyFolder).SubFolders NbFile = NbFile + oFld.Files.count Next If Nbfile >= Cint(Nombre) Then MsgBox "Nombre de fichiers supérieur à " & Nombre ,vbExclamation Set oFSO = Nothing code_retour = 2 Else MsgBox "Nombre de fichiers inferieur à " & Nombre ,vbExclamation Set oFSO = Nothing code_retour = 0 End if End if Wscript.quit(code_retour)
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question@echo off REM 2 paramètres (chemin et nombre de fichiers) call cscript D:\script.vbs D:\Diapositives 100 TTT echo code retour du script.bat = %ERRORLEVEL% pause
Option Explicit Dim objFso, objArgs Dim MyFolder, MyCount, MyErrorLevel MyErrorLevel = 0 Set objArgs = WScript.Arguments If objArgs.Count <> 2 Then WScript.Echo "Erreur sur nombre arguments " & objArgs.Count WScript.Quit(2) End If MyFolder = objArgs(0) WScript.echo MyFolder MyCount = objArgs(1) WScript.Echo MyCount Set objFso = CreateObject("Scripting.FileSystemObject") If objFso.FolderExists(MyFolder) Then Call SearchFolders(objFso.GetFolder(MyFolder), MyCount, MyErrorLevel) Else WScript.echo MyFolder & " -> le répertoire n'existe pas" WScript.Echo "MyErrorLevel -> " & 2 WScript.Quit(2) End If WScript.Echo "MyErrorLevel -> " & MyErrorLevel Set objArgs = Nothing Set objFso = Nothing '####################################################################### Function SearchFolders(ArgFolder, MyCount, MyErrorLevel) Dim subFolder WScript.Echo ArgFolder & vbTab & ArgFolder.Files.Count If ArgFolder.Files.Count >= CInt(MyCount) Then WScript.echo "Nombre de fichiers dépassé !!!" WScript.Echo "MyErrorLevel -> " & 2 WScript.Quit(2) End If For Each subFolder In ArgFolder.SubFolders Call SearchFolders(subFolder, MyCount, MyErrorLevel) Next
Const MyFolder = "C:\tmp" Dim oFSO,oFld Dim NbFile NbFile = 0 Set oFSO = CreateObject("Scripting.FileSystemObject") If oFSO.FolderExists(MyFolder) Then NbFile = oFSO.GetFolder(MyFolder).Files.count For each oFld in oFSO.GetFolder(MyFolder).SubFolders NbFile = NbFile + oFld.Files.count Next If Nbfile >= 5 Then MsgBox "Nombre de fichiers > 5",vbExclamation Set oFSO = Nothing 'wscript.quit(2) Else MsgBox "Nombre de fichiers < 5",vbExclamation Set oFSO = Nothing 'wscript.quit(0) End if End if
@echo off REM 2 paramètres (chemin et nombre de fichiers) call cscript H:\script.vbs H:\Diapositives 95 echo code retour du script.bat = %ERRORLEVEL% pause
Option Explicit Dim objFso, objArgs Dim MyFolder, MyCount, MyErrorLevel MyErrorLevel = 0 Set objArgs = WScript.Arguments If objArgs.Count <> 2 Then WScript.Echo "Erreur sur nombre arguments " & objArgs.Count WScript.Quit(2) End If MyFolder = objArgs(0) WScript.Echo "Racine : " & MyFolder MyCount = objArgs(1) WScript.Echo "Seuil : " & MyCount & " fichiers" WScript.Echo "" Set objFso = CreateObject("Scripting.FileSystemObject") If objFso.FolderExists(MyFolder) Then Call SearchFolders(objFso.GetFolder(MyFolder), MyCount, MyErrorLevel) Else WScript.Echo MyFolder & " -> le repertoire n'existe pas" WScript.Echo "MyErrorLevel -> " & 2 WScript.Quit(2) End If WScript.Echo "MyErrorLevel -> " & MyErrorLevel WScript.Echo "" Set objArgs = Nothing Set objFso = Nothing '####################################################################### Function SearchFolders(ArgFolder, MyCount, MyErrorLevel) Dim subFolder WScript.Echo "" WScript.Echo "Repertoire : " & ArgFolder WScript.Echo "Nombre de fichiers : " & ArgFolder.Files.Count If ArgFolder.Files.Count >= CInt(MyCount) Then WScript.Echo "Nombre de fichiers > ou = au seuil !!!" &_ Space(3) & "MyErrorLevel -> " & 2 WScript.Echo "" WScript.Quit(2) Else WScript.Echo "Nombre de fichiers < au seuil !!! " &_ Space(3) & "MyErrorLevel -> " & MyErrorLevel WScript.Echo "" End If For Each subFolder In ArgFolder.SubFolders Call SearchFolders(subFolder, MyCount, MyErrorLevel) Next End Function
Option Explicit Dim objFso Dim MyFolder, MyCount MyFolder = "C:\tmp" MyCount = 5 Set objFso = CreateObject("Scripting.FileSystemObject") If objFso.FolderExists(MyFolder) Then Call SearchFolders(objFso.GetFolder(MyFolder), MyCount) Else MsgBox MyFolder & " -> le repertoire n'existe pas" &vbCrLf&_ "Fin du script",,ArgFolder WScript.Quit End If Set objFso = Nothing '################################################################ Function SearchFolders(ArgFolder, MyCount) Dim subFolder If ArgFolder.Files.Count >= CInt(MyCount) Then MsgBox "Seuil de fichiers fixé à " & MyCount &vbCrLf&_ "Nombre de fichiers > ou = au seuil car " &_ ArgFolder.Files.Count & " fichiers" &vbCrLf&_ "Fin du script",,ArgFolder WScript.Quit Else MsgBox "Seuil de fichiers fixé à " & MyCount &vbCrLf&_ "Nombre de fichiers < au seuil car " &_ ArgFolder.Files.Count & " fichiers",,ArgFolder End If For Each subFolder In ArgFolder.SubFolders Call SearchFolders(subFolder, MyCount) Next End Functionjean-marc