Scripting Question

Vbscript to find 180days old Logfile from C drive

04/11/2016 802 views
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 
wscript.echo "tr_Oldlogfiles=" &OldFile
wscript.echo "tr_Largelogfiles=" &LargeFile
0 Comments   [ + ] Show comments


All Answers


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

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

View more:


This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ