Sasquatch69
Programmer
Hi, i try to delete all file in a directory where the date is less than a specific date(date - 10 day)
My Code:
If CStr( Day((Now()-NbDay))) < 10 Then
jour = "0" + CStr( Day((Now()-NbDay)))
Else
jour = CStr( Day((Now()-NbDay)))
End if
mois = CStr( Month((Now()-NbDay)))
annee = CStr( Year((Now()-NbDay)))
'creationDate format
dtmTargetDate = annee + mois + jour + "000000.000000+***"
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2"
Set colFiles = objWMIService.ExecQuery _
("SELECT * FROM CIM_DataFile WHERE and CreationDate < '" & dtmTargetDate & "'"
For Each objFile in colFiles
'display file for now..
WScript.StdOut.WriteLine objFile.creationdate
Next
It does'nt work! I Know i can use FileSystemObject(vbscript)
but i want to know which one is more fastest!!(1000 files to delete)
The error is in the select... problem with date!!
Thanks!!
Sorry for my bad english.
My Code:
If CStr( Day((Now()-NbDay))) < 10 Then
jour = "0" + CStr( Day((Now()-NbDay)))
Else
jour = CStr( Day((Now()-NbDay)))
End if
mois = CStr( Month((Now()-NbDay)))
annee = CStr( Year((Now()-NbDay)))
'creationDate format
dtmTargetDate = annee + mois + jour + "000000.000000+***"
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2"
Set colFiles = objWMIService.ExecQuery _
("SELECT * FROM CIM_DataFile WHERE and CreationDate < '" & dtmTargetDate & "'"
For Each objFile in colFiles
'display file for now..
WScript.StdOut.WriteLine objFile.creationdate
Next
It does'nt work! I Know i can use FileSystemObject(vbscript)
but i want to know which one is more fastest!!(1000 files to delete)
The error is in the select... problem with date!!
Thanks!!
Sorry for my bad english.