Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Win/Batch: How to display the "seconds" field in last modified date of a file?  (Read 12965 times)

0 Members and 1 Guest are viewing this topic.

lwkt

    Topic Starter


    Rookie

    Hi,

    I am going to check for any update in a log file.

    My approach is to use a DOS/Batch file to check for the
    last modified date of that file for a certain period of
    time (say 10 seconds).

    I have tried the following command to get and display the last modified date: -

    FOR /f %%m IN ('DIR/b capture.log') DO SET lmdate=%%~tm
    ECHO The last modified date of capture log is: %lmdate%

    The output would be:  dd/mm/yyyy hh:mm  (for example: 29/12/2010 12:00)

    Is it possible to display the last modified date
    format down to the "seconds" field?



    Thanks,
    Thomas

    ghostdog74



      Specialist

      Thanked: 27
      you can use vbscript. this example gets the file modified date to a variable "theDate". Use the second() method to get the seconds. Use Year(), Month() , Day() , Hour(), Minute() to get the other respective times/dates.
      Code: [Select]
      Set objFS = CreateObject( "Scripting.FileSystemObject" )
      strFile=WScript.Arguments(0)
      Set objFile = objFS.GetFile(strFile)
      theDate =  objFile.DateLastModified
      WScript.Echo Second(theDate)


      lwkt

        Topic Starter


        Rookie

        Thanks for your suggestion.

        I'm not familiar with vbscript.

        Do you mind tell me how to implement into DOS/Batch?

        Thanks,
        Thomas

        oldun

        • Guest
        Try this:

        Code: [Select]
        forfiles /m capture.log /c "cmd /c ECHO The last modified date of capture log is: @ftime"

        lwkt

          Topic Starter


          Rookie

          I got the error message" 'FORFILES' is not recognized as an internal or external command,
          operable program or batch file."

          How to get it?

          I'm using WinXP SP3 PC.


          Salmon Trout

          • Guest
          I got the error message" 'FORFILES' is not recognized as an internal or external command,
          operable program or batch file."

          How to get it?

          I'm using WinXP SP3 PC.

          it isn't included in XP. Only Vista or later. However it is part of the Windows 2000 Resource Kit.

          Get it here

          http://www.dynawell.com/download/reskit/microsoft/win2000/forfiles.zip

          Unzip it and copy forfiles.exe to:

          %systemroot%\system32\forfiles.exe

          and it should work.

          Where %systemroot% is a system variable normally pointing to "c:\windows".


          lwkt

            Topic Starter


            Rookie

            Thanks for your input, but my clients does not allow to install extra programs on their machines.

            Let's go back to the approach of vbscript.

            Could anybody teach me how to integrate the vbscript that mentioned by
            "ghostdog74" into a DOS/Batch file?
            Code: [Select]
            Set objFS = CreateObject( "Scripting.FileSystemObject" )
            strFile=WScript.Arguments(0)
            Set objFile = objFS.GetFile(strFile)
            theDate =  objFile.DateLastModified
            WScript.Echo Second(theDate)

            Or is there any other alternative to use native Dos command to get the "seconds" field
            of a file's "last modified date"?

            Thanks,
            Thomas


            Salmon Trout

            • Guest
            Could anybody teach me how to integrate the vbscript that mentioned by
            "ghostdog74" into a DOS/Batch file?
            Code: [Select]
            Set objFS = CreateObject( "Scripting.FileSystemObject" )
            strFile=WScript.Arguments(0)
            Set objFile = objFS.GetFile(strFile)
            theDate =  objFile.DateLastModified
            WScript.Echo Second(theDate)


            Save it somewhere as a .vbs file and call it from the batch file by [path\]name, with the //nologo switch, using the cscript.exe script engine, passing the filename as a parameter (quoted if it contains spaces)

            Code: [Select]
            cscript //nologo scriptname.vbs "filename"
            Note that the file modification time in NTFS or FAT32 is only accurate to 2 seconds anyhow. Are you sure this is the best method?

            Can't you just examine the last line of the log file and see if it has changed?







            lwkt

              Topic Starter


              Rookie

              An accuracy of 2 seconds is not enough as my purpose is to keep track of any update
              of the log file down to every second.

              Tracking of the changes on last line of the log file is a good suggestion.

              Would you mind teach me how to implement in a DOS/batch approach?

              Thanks,
              Thomas