I have wrote a vbscript to find 180days old log file from C drive. Now the problem in below script is , I am able to get all the log file details from C drive.But not 180days old. Can anyone help me to correct my script please.

strComputer = "."
Dim objFile,iDaysOld,item,objFSO,dateTime,Filesize,LargeFile,strCheckDate
Dim FileName,FileName1,Logs,GetFile,file,filemodified,OldFile,LargeFile1
iDaysOld = 180
Set dateTime = CreateObject("WbemScripting.SWbemDateTime")
Set wmi = GetObject("winmgmts:\\.\root\cimv2")
Set files = wmi.ExecQuery("Select * from CIM_DataFile Where Extension='log' AND Drive='C:'")
For Each file in files
If LCase(Right(Cstr(file.Name), 3)) = "log" Then
        FileName1 = Trim(file.Name)
        FileName = (file.Name & "," & FileName)
        Filesize= (file.FileSize)
strCheckDate = strDateCreated
strCheckDate = strDateAccessed
strCheckDate = strDateModified
If strCheckDate < (Date() - iDaysOld) Then
OldFile = (file.Name & "," & OldFile)
End If 
If Filesize >= 104857600 Then
LargeFile = (file.Name & "," & LargeFile)
' oFile.Delete(True) 
    End If 
End If 
Next
wscript.echo "tr_Oldlogfiles=" &OldFile
wscript.echo "tr_Largelogfiles=" &LargeFile
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Answers

2

How many times would you like us to post the link to your original post which asks the same question?

Whilst I appreciate that you didn't understand the solution I posted for you, you haven't even explored the use of DateDiff, which I originally suggested and which you're going to have to use.

If you're not going to purchase a book/tutorial/training course, the only way you're going to learn is by looking at other people's code and experimenting.

Answered 04/11/2016 by: VBScab
Red Belt

Please log in to comment
Answer this question or Comment on this question for clarity