Bonjour,
Voici un script vbs qui sert a supprimmer des fichiers obsolètes dans un dossier et ses sous dossiers (grâce à votre aide ). Comment le modifier afin qu'il ne recherche qu'une extension de fichier par exemple .pdf ?
Par avance merci.

le code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 Dim DossierSauvegarde 'Nom du répertoire à parcourir
Dim oFSO,oFld,oSubFolder,strFileSize,ws,NomFichierLog,temp,PathNomFichierLog,OutPut
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set ws = CreateObject( "Wscript.Shell" )
Title = "Suppression des Fichiers"
'Nombre de jours de conservation des Fichiers 
AgeMaximalFichiers = "8" 
'Comptage des fichiers effaces 
NbFichiersEffaces = 0 
NomFichierLog= "Fichiers Supprimés_"& Day(Now)&"_"& Month(Now)&"_"& year(Now) &".txt"
temp = ws.ExpandEnvironmentStrings("%temp%")
PathNomFichierLog = temp & "\" & NomFichierLog
Set OutPut = oFSO.OpenTextFile(temp & "\" & NomFichierLog,2,True)
DossierSauvegarde = "D:\Scanner\"
'On verifie que le repertoire de sauvegarde existe 
If (myName = Winrep = oFSO.FolderExists(DossierSauvegarde)) = False Then 
    Erreur = MsgBox("Le dossier de sauvegarde est introuvable !",16,"Test d'existence du dossier" ) 
    Wscript.Quit 
End If 
 
'On recupere la date système 
DateSysteme = Date
ParcoursRep DossierSauvegarde
wscript.sleep 3000
If MsgBox ("Voulez-vous consulter le fichier journal : " & qq(NomFichierLog),VbYesNo+VbQuestion ,Title ) = VbYes Then
Explorer(PathNomFichierLog)
else
wscript.quit
end if
 
Sub ParcoursRep (stRep )
    MsgBox "On Traite le Répertoire : " & qq(stRep),64,qq(stRep)
	If oFSO.FolderExists(stRep) Then
	Set oFld = oFSO.GetFolder(stRep)
	end If
output.writeLine "Le Nom et le chemin du répertoire :" & qq(oFld.Path)  & " et il contient " & oFld.SubFolders.count & " sous-répertoires"
output.writeline String(100,"*")
 
For each File in oFld.Files
If (DateDiff("d", File.DateLastModified, DateSysteme) > CInt(AgeMaximalFichiers)) Then 
'On verifie qu'ils ne sont pas en lecture seule 
If File.Attributes And 1 Then File.Attributes = File.Attributes - 1
OutPut.WriteLine File.Path 
'Msgbox File.Path,64,File.Path
File.Delete()
NbFichiersEffaces = NbFichiersEffaces + 1 
End If 
Next
output.writeLine "Il y a "& oFld.Files.count & " Fichiers dans le dossier "& qq(oFld.Path)  
output.writeline String(100,"*")
 
	For each oSubFolder in oFld.subFolders
		ParcoursRep oSubFolder.Path 'appel récursif de la procédure
	Next
end sub
 
OutPut.Writeline Cstr(NbFichiersEffaces) + " fichiers ont été supprimés !"
MsgBox (Cstr(NbFichiersEffaces) + " fichiers ont été supprimés !" ),64,Cstr(NbFichiersEffaces) + " fichiers ont été effacés"
 
Function qq(strIn)
    qq = Chr(34) & strIn & Chr(34)
End Function
 
Function Explorer(File)
    Set ws=CreateObject("wscript.shell")
    ws.run "Explorer.exe "& File & "\",0,True
end Function