Computer Hope

Microsoft => Microsoft DOS => Topic started by: lwkt on December 28, 2010, 09:51:20 PM

Title: Win/Batch: How to display the "seconds" field in last modified date of a file?
Post by: lwkt on December 28, 2010, 09:51:20 PM
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
Title: Re: Win/Batch: How to display the "seconds" field in last modified date of a file?
Post by: ghostdog74 on December 28, 2010, 11:46:48 PM
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)

Title: Re: Win/Batch: How to display the "seconds" field in last modified date of a file?
Post by: lwkt on December 29, 2010, 12:15:05 AM
Thanks for your suggestion.

I'm not familiar with vbscript.

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

Thanks,
Thomas
Title: Re: Win/Batch: How to display the "seconds" field in last modified date of a file?
Post by: oldun on December 29, 2010, 02:47:22 AM
Try this:

Code: [Select]
forfiles /m capture.log /c "cmd /c ECHO The last modified date of capture log is: @ftime"
Title: Re: Win/Batch: How to display the "seconds" field in last modified date of a file?
Post by: lwkt on December 29, 2010, 03:02:49 AM
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.

Title: Re: Win/Batch: How to display the "seconds" field in last modified date of a file?
Post by: Salmon Trout on December 29, 2010, 11:52:05 AM
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".

Title: Re: Win/Batch: How to display the "seconds" field in last modified date of a file?
Post by: lwkt on December 29, 2010, 07:54:24 PM
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

Title: Re: Win/Batch: How to display the "seconds" field in last modified date of a file?
Post by: Salmon Trout on December 30, 2010, 12:26:14 AM
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?






Title: Re: Win/Batch: How to display the "seconds" field in last modified date of a file?
Post by: lwkt on December 30, 2010, 01:18:36 AM
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