Batch ตรวจสอบ date modified ว่าตรงกับวันที่ปัจจุบันหรือไม่ และแสดงสีข้อความ

Batch ตรวจสอบ date modified ว่าตรงกับวันที่ปัจจุบันหรือไม่ และแสดงสีข้อความ

 ไฟล์ชื่อ test1 และ test3 วันที่ ล่าสุด 08/04/2561 
ผลที่ออกมา


@echo off
SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
  set "DEL=%%a"
)
SET filename1="test1.txt"
SET filename2="test3.txt"
FOR %%f IN (%filename1%) DO SET filedatetime1=%%~tf
FOR %%f IN (%filename2%) DO SET filedatetime2=%%~tf
SET filedate1=%filedatetime1:~0,-9%
SET filedate2=%filedatetime2:~0,-9%
SET date1=%date:~4%
set dd=%date:~4,2%
set mm=%date:~7,2%
set yy=%date:~10,4%
SET /A date2=%dd% - 1
SET date3=%date2%/%mm%/%yy%

IF "%filedate1%"=="%date1%" (
call :ColorText 0a "File test1.txt OK"
echo  Date modified %filedatetime1% today %date1%
  ) ELSE (
call :ColorText 0C "File test1.txt Not OK"
echo  Date modified %filedatetime1% today %date1%
)
IF "%filedate2%" == "%date1%" (
call :ColorText 0a "File test3.txt OK"
echo  Date modified %filedatetime2% today %date1%
    ) ELSE (
call :ColorText 0C "File test3.txt Not OK"
echo  Date modified %filedatetime2% today %date1%
    )
pause:
goto :eof
:ColorText
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
goto :eof

แสดงความคิดเห็น

0 ความคิดเห็น