Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 664
user3133076 Avatar asked Sep 13 '25 21:09

user3133076


1 Answers

In Windows 7 and forward (or via Resource Kit for XP) you can use forfiles for this. Something like:

forfiles /m *.* /c "cmd /c ECHO The last modified date of: @file is: @ftime"

In a directory with the following files:

myTest.txt
myTest2.txt

I get:

The last modified date of: "myTest.txt" is: 13:21:07
The last modified date of: "myTest2.txt" is: 13:21:20
like image 136
Ebbe M. Pedersen Avatar answered Sep 16 '25 13:09

Ebbe M. Pedersen