3

I want to know when a file has been modified for the last time.

I can get these infos using the following batch script:

FOR %%i IN (myfile) DO SET modif_time=%%~ti

The problem is how to get the second of the last modification ? and the command %~t returns the date and the time with only hours and minutes.

I can only check the seconds by manually viewing the "property window" file by file.

How can I get the time with seconds in batch?

Hackoo
  • 115
  • 5

1 Answers1

1

Using a Powershell snippet, you can overcome the console limitation:

FOR /f "usebackq tokens=2,3 skip=3" %%i IN (`powershell.exe "& {get-childitem .\foo -force | Select-Object FullName,LastWriteTime}"`) do set modif_time=%%i %%j

Also, take a look at this wmic.exe snippet:

wmic datafile where name='c:\\temp\\myfile' get LastModified

The output looks like:

LastModified
20150807125810.203014-420

Which may also be suitable for you.

RobW
  • 2,766
  • 1
  • 17
  • 22
  • Lastly there is forfiles: FORFILES /S /M *.cmd /C "cmd /c echo @fname @ftime" There may be easier ways to express this, but the above gives a filename, and its time stamp expressed in hh:mm:ss – RobW Jul 17 '19 at 05:17