VB Script to get Last Modofication date – ERROR

5 pts.
Tags:
Microsoft Visual Basic
Hi gurus,

In the below code I'm trying to fetch the Date Last modified of a file, but I am getting an error that syntax in Line 135,37 error at:
SET TargetFile = ObjFso.getfile(objFile.Filename)
Context.LogMessage("Modified Date = " & TargetFile.DateLastModified)
Below is the code:
Const ForAppending = 8,   ForReading = 1,   ForWriting = 2
 
MyDate = Replace (Now, ":", "")
MyDate = Replace (MyDate, "/", "")
MyDate = Replace (MyDate, " ", "")
strLogDir = "D:dataPushQueryUtilityE15logs"
ScriptLogFile = strLogDir & left (wscript.scriptname, len (wscript.scriptname) -4) & "_" & MyDate & ".log"
 
 
 
issUser="user"
issPassword="password"
 
Rem Main Function Which calls the other
 
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
 
Set storesFile = objFSO.opentextfile("RDY.txt", 1, true)
 
Do Until storesFile.atendofstream
 
    objtext = storesFile.readline
    buff = Split(objtext, " ")
    storeno = buff(0)
    writelog "" & storeno & ""
                
    strComputer = "UK0" & storeno & "ISS01.S" & storeno & ".TSL"
    strUser = "UK0" & storeno & "ISS01" & issUser
'   writelog strComputer
'  writelog strUser
    
                CheckFile storeno, strComputer, strUser, issPassword, LastModified, LastAccessed
                
                
                writelog "-----------------------------------"
                                
Loop
 
storesFile.close
 
 
Function CheckFile (storeno, strComputer, strUser, issPassword)
DIM TargetFile
 
                Set objLocator = CreateObject( "WbemScripting.SWbemLocator" )
 
    Set objWMIService = objLocator.ConnectServer ( strComputer, "rootCIMV2", strUser, issPassword )
 
    objWMIService.Security_.impersonationlevel = 3
 
    Set objFSO = CreateObject("Scripting.FileSystemObject") 
 
    Set objFolder = objWMIService.ExecQuery("Select * FROM CIM_DataFile WHERE Drive = 'D:' AND Path = 'IMP'") 
 
                If Err.number <> 0 Then 
                                writelog "Problem with DataFile set1" 
                End If 
 
      For Each objFile in objFolder
                                
                                
                                a = objFile.Filesize
                '               WScript.Echo a
                                b = filesize(a)
                                If UCase(objFile.Filename) = "RDY" and objFile.Extension = "zip" then
SET TargetFile = ObjFso.getfile(objFile.Filename)
Context.LogMessage("Modified Date = " & TargetFile.DateLastModified)
                                   
writelog objFile.Filename&vbtab&
 
  
                                End If
 
      Next
                
End Function
 
Function filesize(bytes) 
 
    Filesize = bytes / 1024 
    Filesize = Round(Filesize, 2) 
 
        If FileSize < 0.5 Then 
 
            Filesize = Filesize * 1024 
            Filesize = Int(FileSize) 
            Filesize = Filesize & " Bytes" 
 
        ElseIf Filesize > 1024 Then 
 
            FileSize = Filesize / 1024 
            FileSize = Round(FileSize, 2) 
            FileSize = Filesize & " MB" 
 
        Else 
 
            filesize = filesize & " KB" 
     
        END If 
 
End Function 
 
Sub writelog (LogData)
 
Dim LogFile
 
WScript.Echo LogData
if Not objFSO.fileexists (ScriptLogFile) then
   Set LogFile=objFSO.createtextfile (ScriptLogFile)
Else
   Set LogFile=objFSO.opentextfile (ScriptLogFile, 8)
end If
 
   logfile.writeline (LogData)
   logfile.close
 
End Sub


Software/Hardware used:
Microsoft Visual Basic

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following