A voir également:
- VBS : Purge de dossiers et sous-dossiers
- Vbs windows - Accueil - Optimisation
- Vbs - Télécharger - Édition & Programmation
- Vbs editor - Télécharger - Édition & Programmation
- Fichier vbs ✓ - Forum Virus
- Vbs malware gen ✓ - Forum Virus
1 réponse
Le mien est mieu si tu veux et fonctionnel
Removal_files.vbs
supprime les fichier qui date de plus de X jours, les valeurs en gras sont a modifier.
et removal_folder.vbs
Supprime dossier, sous dossier vide.
Removal_files.vbs
supprime les fichier qui date de plus de X jours, les valeurs en gras sont a modifier.
strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2" ) Set objFSO = CreateObject("Scripting.FileSystemObject" ) Set objShell = CreateObject("Shell.Application" ) strFolderName = ("Chemin du dossier") Set colSubfolders = objWMIService.ExecQuery _ ("Associators of {Win32_Directory.Name='" & strFolderName & "'} " _ & "Where AssocClass = Win32_Subdirectory " _ & "ResultRole = PartComponent" ) arrFolderPath = Split(strFolderName, "\" ) strNewPath = "" For i = 1 to Ubound(arrFolderPath) strNewPath = strNewPath & "\\" & arrFolderPath(i) Next strPath = strNewPath & "\\" Set colFiles = objWMIService.ExecQuery _ ("Select * from CIM_DataFile where Path = '" & strPath & "'" ) For Each objFile in colFiles Set objReadOnlyFile = objFSO.GetFile(objFile.Name) 'Wscript.Echo objFile.Name & chr (10) & objReadOnlyFile.DateLastModified if DateDiff("d",objReadOnlyFile.DateLastModified ,Date)>15 then objFile.delete end if Next For Each objFolder in colSubfolders GetSubFolders strFolderName Next Sub GetSubFolders(strFolderName) Set colSubfolders2 = objWMIService.ExecQuery _ ("Associators of {Win32_Directory.Name='" & strFolderName & "'} " _ & "Where AssocClass = Win32_Subdirectory " _ & "ResultRole = PartComponent" ) For Each objFolder2 in colSubfolders2 strFolderName = objFolder2.Name arrFolderPath = Split(strFolderName, "\" ) strNewPath = "" For i = 1 to Ubound(arrFolderPath) strNewPath = strNewPath & "\\" & arrFolderPath(i) Next strPath = strNewPath & "\\" Set colFiles = objWMIService.ExecQuery _ ("Select * from CIM_DataFile where Path = '" & strPath & "'" ) For Each objFile in colFiles Set objReadOnlyFile = objFSO.GetFile(objFile.Name) if DateDiff("d",objReadOnlyFile.DateLastModified ,Date)>15 then 'Wscript.Echo objFile.Name & chr (10) & objReadOnlyFile.DateLastModified objFile.delete end if Next GetSubFolders strFolderName Next End Sub
et removal_folder.vbs
Supprime dossier, sous dossier vide.
Option Explicit Const pfad = ("Chemin du dossier") Dim Text, Title, index, Txt() Dim fso, wsh, i index = 1 Set wsh = WScript.CreateObject ("WScript.Shell") Set fso = WScript.CreateObject("Scripting.FileSystemObject") RecFolder index, wsh.ExpandEnvironmentStrings(pfad) Function RecFolder (idx, pfad) Dim fo, fc, i, colFiles, file Set fo = fso.GetFolder(pfad) Set fc = fo.SubFolders Set colFiles = fo.Files For Each i in fc Call RecFolder (idx+1, pfad + "\" + i.name) If i.Files.Count = 0 And i.SubFolders.Count = 0 Then fso.DeleteFolder(pfad + "\" + i.name) End if Next End function