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?

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.