J'ai ceci :
Quand je choisis un dossier qui n'a pas de sous-dossier il marche ; mais quand je choisi un dossier qui a un sous-dossier il beugle ici :
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85 '******************************************************************************* ' Script permettant D 'effacer les fichiers Qui date de plus de 15 jours ' Avec interface Graphique ' '******************************************************************************* Private Sub Form_Load() 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 Set colSubfolders = objWMIService.ExecQuery _ ("Associators of {Win32_Directory.Name='" & strFolderName & "'} " _ & "Where AssocClass = Win32_Subdirectory " _ & "ResultRole = PartComponent") 'Wscript.Echo strFolderName 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 End Sub 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) > 15 Then 'Wscript.Echo objFile.Name & chr (10) & objReadOnlyFile.DateLastModified objFile.Delete End If Next GetSubFolders strFolderName Next End Sub
Merci d'avance
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 Set colSubfolders2 = objWMIService.ExecQuery _ ("Associators of {Win32_Directory.Name='" & strFolderName & "'} " _ & "Where AssocClass = Win32_Subdirectory " _ & "ResultRole = PartComponent")
Partager