batch script

  • Hi,

    how to check if a file or folder is modified or not using a batch script?

    Thanks,

    Natalie.

  • Do you want to see the results "on-the-fly" through a message box, or is it part of a bigger plan like a DTS package or other function?

  • Natalie,

    Paste the following in the Notepad, save it as a file name CheckModifyDate.vbs:

    If IsLatest("C:\z_MyLog1.txt") = "False" Then

     MsgBox "Your file was not modified today!"

    Else

     MsgBox "Your file was modified today!"

    END IF

    '----------------------------------------------------------------------

    Private Function IsLatest(MyFileName)

    '----------------------------------------------------------------------

     On Error Resume Next

         Dim oFSO

     Dim MyFile

     Set oFSO = CreateObject("Scripting.FileSystemObject")

      IsLatest = "False"

     Set MyFile = oFSO.GetFile(MyFileName)

      If MyFile.DateLastModified >= Date Then

       IsLatest = "True"

     End If

     Set oFSO = Nothing

    End Function

    You can run this VBscript file calling it from the batch as

    cscript CheckModifyDate.vbs

    I would advise to specify the full path to the script like

    cscript "C:\MyScripts\CheckModifyDate.vbs"

    You have to also modify the VBscript to specify the file or a folder name instead of "C:\z_MyLog1.txt". Replace the message boxes in IF statement with the processing you would like if the Modify Date on the file changes. Function Date that I use gives the current date, you may replace it for what you need.

    Regards,Yelena Varsha

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply