On Sunday, 9 July 2017 13:29:58 UTC+1,
petu...@googlemail.com wrote:
> On Saturday, 8 July 2017 16:17:52 UTC+1, Dr J R Stockton wrote:
> > I have the following code, which shows me the local date-time of
> > TRY.LOG as YYYY-MM-DD HH:MM - but I want YYYY-MM-DD HH:MM:SS .
> >
> > if %%f==TRY.LOG (
> > echo Found TRY.LOG %%~tf, new files follow :-
> > )
> >
> > Any suggestions that are not too complex or slow?
> You could use WMIC, whose speed can be acceptable as long as it receives a full file path as its input file specification.
>
> The following example takes a single input as a filename, best implemented by dragging and dropping a file onto the script:
I need it in the middle of an existing batch file. TRY.LOG is a zero-length file used as a marker in date-sorted directory output, re-created after each run and created at the beginning by "IF NOT EXIST TRY.LOG ...", so its checks are not needed. The working code I've derived from yours follows yours (one long line is wrapped here in each). It uses %CD% because the code, and more, is surrounded by PUSHD %Diry% and POPD.
> ::----- START -----
> @ECHO OFF
> SET "_I=%~1"
> IF NOT DEFINED _I (GOTO :EOF) ELSE IF NOT EXIST "%~1" GOTO :EOF
> SET "_M="
> FOR /F "SKIP=1 DELIMS=" %%A IN ('WMIC DATAFILE WHERE "NAME='%_I:\=\\%'"^
> GET LASTMODIFIED 2^>NUL') DO FOR %%B IN (%%~nA) DO SET "_M=%%B"
> IF NOT DEFINED _M (GOTO :EOF
> ) ELSE SET "_M=%_M:~,4%-%_M:~4,2%-%_M:~6,2% %_M:~8,2%:%_M:~10,2%:%_M:~12,2%"
> ECHO %_M%
> PAUSE
> ::------ END ------
SET _I=%CD%\TRY.LOG
FOR /F "SKIP=1 DELIMS=" %%A IN ('WMIC DATAFILE WHERE "NAME='!_I:\=\\!'"^
GET LASTMODIFIED') DO FOR %%B IN (%%~nA) DO SET "_M=%%B "
IF NOT DEFINED _M (set "_M=WMIC datetime fault"
) ELSE SET
"_M=!_M:~,4!-!_M:~4,2!-!_M:~6,2! !_M:~8,2!:!_M:~10,2!:!_M:~12,2!"
ECHO Seen TRY.LOG !_M!, newer files follow it :-
I've not yet understood the "FOR %%B IN (%%~nA) DO" .
The "NOT DEFINED" case should never be able to occur.
I was not wanting to use an auxiliary program here; but I have since realised and tested that the following command line works, where COLS is a Pascal/Delphi program of mine (line has wrapped).
Prompt>wmic datafile where "name='c:\\homepage\\try.log'" get lastmodified
| COLS ^&2 'Prefix * 0-4 '- 5-6 '- 7-8 * 9-10 ': 11-12 ': 13-14 * 'postfix .
gives
Prefix 2017-07-11 22:08:52 postfix
Thanks.