0

これを使用して、ファイルの変更日を取得しています。

@echo off
FOR %%? IN ("C:\some.exe") DO (
    ECHO Last-Modified Date   : %%~t?
)

上記は、Last-Modified Date : 26/03/2013 14:43 のようなものを返します。

上記の日付部分を取得して、名前に日付が含まれる別のファイル、つまり 23-Sep-13.exe と比較するにはどうすればよいですか?

名前に日付を含むファイルがファイルの変更されたバージョンよりも新しい場合、つまり更新をインストールする場合は、バッチ ファイルでコードを実行できる必要があります。

4

1 に答える 1

1
@ECHO OFF
SETLOCAL
:: No doubt for international use, this could be retrieved from the registry
SET monthnames=Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
:: get last modified date of target file - your format as specified
:: (I used THIS BATCH FILE)
FOR %%i IN ("%~f0") DO SET target=%%~ti
:: parse the target date
FOR /f "tokens=1-3delims=/ " %%i IN ("%target%") DO SET targetf=%%k%%j%%i
::
:: parse name from 'other file'
SET other=23-Sep-13.exe
FOR /f "tokens=1-3delims=.- " %%i IN ("%other%") DO SET od=%%i&SET omn=%%j&SET oy=%%k
:: Convert monthname to number
:: @ECHO on
SET om=101
FOR %%i IN (%monthnames%) DO (
IF DEFINED omn IF /i %omn%==%%i (SET omn=) ELSE (SET /a om+=1)
)
:: Build date of 'other file' in same format (YYYYMMDD)
SET otherf=20%oy%%om:~-2%%od%
ECHO is %other% later than %target% ?
ECHO IF %otherf% gtr %targetf% GOTO later
ECHO.
::
:: parse name from 'another other file'
SET other=23-Jan-13.exe
FOR /f "tokens=1-3delims=.- " %%i IN ("%other%") DO SET od=%%i&SET omn=%%j&SET oy=%%k
:: Convert monthname to number
SET om=101
FOR %%i IN (%monthnames%) DO (
IF DEFINED omn IF /i %omn%==%%i (SET omn=) ELSE (SET /a om+=1)
)
:: Build date of 'other file' in same format (YYYYMMDD)
SET otherf=20%oy%%om:~-2%%od%
ECHO is %other% later than %target% ?
ECHO IF %otherf% gtr %targetf% GOTO later
ECHO.

コードは、(このバッチ) の日付をターゲット (your 'C:\some.exe'- change to suit.

次に、test を 2 つの異なるfilename-is-date+ext形式のファイル名に適用してテストします。

20 世紀の日付との比較が必要な場合は、簡単に調整できます... :)

于 2013-03-28T03:39:36.773 に答える