I have this code that echos if a file has been modified today or not. How can I add so it can echo not only that the file was modified today, but also at what time?
Like for example "File modified today at %modifytime%".
@echo off
for %%F in (C:\temp\file.txt) do (for /F %%D in ("%%~tF") do (set mdate=%%D))
for /F "tokens=2" %%D in ('date/t') do set cdate=%%D
if "%date%"=="%mdate%" echo File modified today
if not "%date%"=="%mdate%" echo File not modified today
Here's an quick idea using the built-in ForFiles
command:
@Echo Off
For %%A In ("C:\temp\file.txt") Do (If Not "%__CD__%"=="%%~dpA" PushD "%%~dpA"
ForFiles /M "%%~nxA" /D 0 /C^
"Cmd /C Echo @File was modified today0x09@fDate @fTime"2>Nul||(
Echo "%%A" not modified today))
Pause
As with your example, this idea allows you to replace the single file between the parentheses on line 3 with:
*
to output for every file in the current directory. "C:\\temp\\file1.txt" "C:\\somewhere\\fileZ.exe"
to output for multiple known files. PushD
without a PopD
may restrict the number of different directories; if using this option please use sparingly. For safety, I recommend your entries between those parentheses be double quoted.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.