batch - время последнего изменения файла с секундами

14260
user3133076

Я хочу знать, когда файл был изменен в последний раз.

Я могу получить эту информацию, используя следующий пакетный скрипт:

FOR %% i IN (myfile) УСТАНОВИТЬ modif_time = %% ~ ti

Проблема в том, что мне нужна вторая из последних модификаций, и команда %~tвозвращает дату и время только с часами и минутами.

Я могу проверить секунды только вручную, просматривая файл «Окно свойств» файл за файлом.

Как я могу получить время с секундами в партии?

5
Вы ** действительно уверены **, что с помощью `dir / od` файлы` сортируются "случайным образом", если они сделаны в одну и ту же минуту? Для меня `cmd` делает сортировку правильно (несмотря на то, что она не показывает секунды). Вы можете следовать [этим] (http://superuser.com/questions/91287/windows-7-file-properties-date-modified-how-do-you-show-seconds#470017) инструкциям, чтобы получить секунды в диалог свойств в проводнике, чтобы убедиться. Rik 10 лет назад 0
И если вам действительно нужны секунды в вашем скрипте, вы можете подумать о выполнении команды powerscript, чтобы получить его. См [здесь] (http://superuser.com/questions/591438/how-can-i-display-the-time-stamp-of-a-file-with-seconds-from-the-command-line#591459 ) для решения. Rik 10 лет назад 1
Я снова контролировал, и файлы НЕ сортируются случайным образом, но правильным образом, даже если минута одинакова. Может быть, я сделал что-то не так, когда впервые проверил. Моя ошибка Спасибо. @Rik user3133076 10 лет назад 0

2 ответа на вопрос

6
and31415

Windows Vista / 7 and later

Windows Server 2003 and later

With a little effort you can use forfiles to get the last modified time of a specific file, seconds included:

REM "delims=" is required to avoid stripping AM/PM for /f "delims=" %%i in ('"forfiles /m filename /c "cmd /c echo @ftime" "') do set modif_time=%%i echo %modif_time% 

Example output

7:33:54 AM 

The value displayed is based on the local time of the computer and matches the time shown in the file properties dialog.

Usage help

http://technet.microsoft.com/en-us/library/cc753551.aspx


Windows XP

forfiles.exe is not available out of the box, however you can manually get the required executable. It's an old version which is part of the Windows 2000 Resource Kit. The syntax is case-sensitive and slightly different, and so is the output:

for /f %%i in ('"forfiles.exe -mfilename -c"cmd /c echo @FTIME" "') do set modif_time=%%i echo %modif_time% 

Example output

153354 

Here the time value is displayed in the UTC format and is not affected by changes in time zone or daylight saving time. In this example the file was last modified at 15:33:54 (UTC).

Note You can obtain the newer forfiles.exe version by grabbing a copy of the file from any Windows 2003 Server installation or setup media.

0
JdeBP

Используйте интерпретатор команд, который способен на это.

Вот как это сделать с помощью TCC / LE от JP Software, с некоторыми изменениями в теме, добавленными для хорошей меры:

[C:\Users\JdeBP]touch /c myfile 10/01/2014 18:31:32.710 C:\Users\JdeBP\myfile  [C:\Users\JdeBP]echo myfile was created at %@filetime[myfile,c,s] myfile was created at 18:31:32  [C:\Users\JdeBP]echo myfile was last accessed at %@filetime[myfile,a,s] myfile was last accessed at 18:31:32  [C:\Users\JdeBP]for i in (myfile) do set modif_time=%@filetime[%i,w,s]  [C:\Users\JdeBP]echo myfile was last modified at %modif_time% myfile was last modified at 18:31:32 

дальнейшее чтение

Похожие вопросы