cs_vyper55
Messages postés3Date d'inscriptionmercredi 22 mars 2006StatutMembreDernière intervention29 janvier 2007
-
29 janv. 2007 à 15:27
cs_JMO
Messages postés1854Date d'inscriptionjeudi 23 mai 2002StatutMembreDernière intervention24 juin 2018
-
30 janv. 2007 à 06:05
je suis débutant en vbs,
j'ai recupérer ce script qui permet de nettoyer les fichiers de plus de x jours avec une interface graphique
le but de lancer ce programme tout les x jour de la semaine ou du moi sur un serveur et ainsi nettoyer des répertoires des utilisateurs
donc le lancer au travers d'un batch en automatique via le planificateur de tâches
et pour cela je souhaiterai retirer l'interface graphique du programme afin de le lancer comme un batch sans intervention d'un utilisateur ou d'un admin system
merci ci-dessous le script
'*******************************************************************************
' Script permettant D 'effacer les fichiers Qui date de plus de 15 jours
' Avec interface Graphique
'
'*******************************************************************************
strComputer = "."
Set objWMIService = GetObject("winmgmts:\" & strComputer & "\root\cimv2")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder _
(WINDOW_HANDLE, "Selectionner le dossier à traiter :", NO_OPTIONS, ".")
Set objFolderItem = objFolder.Self
strFolderName = objFolderItem.Path
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)>90 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
'Wscript.Echo
'Wscript.Echo 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)>90 then
'Wscript.Echo objFile.Name & chr (10) & objReadOnlyFile.DateLastModified
objFile.delete
end if
Next
GetSubFolders strFolderName
Next
End Sub
Set FSO = CreateObject("Scripting.FileSystemObject")
set folder = FSO.GetFolder (path)'utilisation du FSO pour prendre le dossier
For Each B in folder.subfolders 'pour chaque dossier dans le dossier racine
If B.size = 0 Then 'si la taille du dossier est egal a 0 (donc vide)
'msgbox B & B.size 'effacer le dossier
FSO.DeleteFolder B, force = yes
End If 'fin du SI
cs_JMO
Messages postés1854Date d'inscriptionjeudi 23 mai 2002StatutMembreDernière intervention24 juin 201827 29 janv. 2007 à 16:00
Re,
Attention:
Quand vous proposez un code (ou bout), il faut toujours protéger les actions néfastes du code.
En l'occurrence, ici:
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)>90 then
''''''''''''' objFile.delete
end if
Next
Et surtout, ne jamais tester un tel code !!!! ne pas oublier que :
strComputer = "." c'est soi-même.
jean-marc
Vous n’avez pas trouvé la réponse que vous recherchez ?
cs_vyper55
Messages postés3Date d'inscriptionmercredi 22 mars 2006StatutMembreDernière intervention29 janvier 2007 29 janv. 2007 à 16:13
bonjour jean-marc
merci de la réponse,
il s'agit d'un script que j'ai récupéré et fonctionne avec une interface grpahique l'utilisateur est invité à choisir au travers d'une interface graphique le repertoire racine.
cs_vyper55
Messages postés3Date d'inscriptionmercredi 22 mars 2006StatutMembreDernière intervention29 janvier 2007 29 janv. 2007 à 16:21
ce script marche tres bien avec l'interface graphique, seulement le probleme c'est que j'aimerai l'exploiter sans cette interface et a ce niveau je suis archi débutant en vbs mon domaine c'est le reseau, linux et windows serveur (sytem et reseau, droit d'acces, web iis apache).
et donc en developpement vbs je suis nul.
PCPT
Messages postés13272Date d'inscriptionlundi 13 décembre 2004StatutMembreDernière intervention 3 février 201847 29 janv. 2007 à 18:26
salut,
vyper55 -> le bouton "réponse acceptée" sert à marquer la ou les réponse qui solutionne(nt) ton problème.
si tu valides tout, plus personne ne viendra pour essayer de le résoudre...
corrigé
et évite les topics en doublon stp (je suppose que c'était involontaire)
supprimé
tous les autres -> le doublon est supprimé mais j'ai conservé au bloc-note, donc si une de vos réponses est à remettre ici... profitez avant la fin du monde ou une coupure de courant ^^
++
PCPT [AFCK]
<hr size="2" width="100%" />Prenez un instant pour répondre à [infomsg_SONDAGE-POP3-POUR-CS_769706.aspx ce sondage] svp
cs_JMO
Messages postés1854Date d'inscriptionjeudi 23 mai 2002StatutMembreDernière intervention24 juin 201827 30 janv. 2007 à 06:05
Bonjour à tous
726766 vyper55 , j'ai adapté "ton" code pour qu'il puisse afficher les fichiers non modifiés depuis 15 jours dans un
répertoire. J'ai enlevé la gestion des sous-répertoires, ainsi que l'objet Shell.
arrFolderPath = Split(strFolderName, "")
strNewPath = ""
For i = 1 to Ubound(arrFolderPath)
strNewPath = strNewPath & "\" & arrFolderPath(i)
Wscript.Echo "vérif strNewPath : " &vbCrLf& strNewPath
Next
strPath = strNewPath & "\"
Wscript.Echo "vérif strPath : " &vbCrLf& strPath
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 "vérif suppression fichier (date>15) " & vbCrLf& _
objFile.Name & chr (10) & objReadOnlyFile.DateLastModified
''''''''''''''''''''''objFile.delete
end if
Next
Set objWMIService = Nothing
Set objFSO = Nothing
Set colSubfolders = Nothing
Set colFiles = Nothing
Set objReadOnlyFile = Nothing