Search code examples
batch-filetimestamplast-modifiedseconds

batch - File last modification time with seconds


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 that I need 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?


Solution

  • wmic datafile where name="FileName" get LastModified
    

    FileName must contain the full path with double backspaces.


    Sorting example (recent first):

    for /f "delims=" %a in ('wmic datafile where "drive='c:' and path='\\windows\\'" get LastModified^,Name /format:table^|find ":"^|sort /r') do @echo %a