Package to check if a single file has been modified

I need to check the external directory if one file (example.avi) is modified / created today, and if the answer is yes, start another batch or close.

I found several posts, but I can not make this batch file from myself.

Hope someone can help me. Thank you in advance.

+3
source share
3 answers

The script you found seems correct to me if you start new lines in the correct position. You can add an echo statement before the if statement to see if cdate and mdate have the correct value. And check if the myprogram.bat file exists in the directory. Here is a modified version that shows this. Can you try this and post the output if it doesn't work?

@echo off 
for %%F in (C:\TEST\myfile.avi) do (for /F %%D in ("%%~tF") do (set mdate=%%D)) 
for /F "tokens=2" %%D in ('date/t') do set cdate=%%D
echo cdate="%cdate%"  mdate="%mdate%" current dir=%cd%
if "%cdate%"=="%mdate%" going to start myprogram.bat
if "%cdate%"=="%mdate%" start myprogram.bat
pause

edit Here is a version that works regardless of regional settings. It is based on this decision.

@echo off 
reg copy "HKCU\Control Panel\International" "HKCU\Control Panel\International-Temp" /f > NUL
reg add "HKCU\Control Panel\International" /v sShortDate /d "yyMMdd" /f > NUL
for %%F in (C:\TEST\myfile.avi) do (for /F %%D in ("%%~tF") do (set mdate=%%D)) 
for /F "tokens=1" %%D in ("%date%") do set cdate=%%D
echo cdate="%cdate%"  mdate="%mdate%" current dir=%cd% date="%date%"
reg copy "HKCU\Control Panel\International-Temp" "HKCU\Control Panel\International" /f > NUL
if "%cdate%"=="%mdate%" start myprogram.bat

First, he backs up the shortdate format in the registry. Then he replaces it with yyMMdd. Now it looks for the file modification date and current date. before comparing dates, it restores the short date format.

+1
source

, Win XP.

@echo off
for %%F in (C:\TEST\myfile.avi) do (for /F %%D in ("%%~tF") do (set mdate=%%D))
for /F "tokens=2" %%D in ('date/t') do set cdate=%%D

if "%cdate%"=="%mdate%" start myprogram.bat
+1
DIR %1 | FIND /I "%1" > ~ISMODIF.TMP
ECHO.>> ~ISMODIF.TMP
TYPE ~ISMODIF.TMP | TIME | FIND /I "%1" > ~ISMODIF.BAT
ECHO SET CHKDATE=%%4> ENTER.BAT
CALL ~ISMODIF.BAT
DIR ~ISMODIF.BAT | FIND /I "~ISMODIF.BAT" > ~ISMODIF.TMP
ECHO.>> ~ISMODIF.TMP
TYPE ~ISMODIF.TMP | TIME | FIND /I "~ISMODIF.BAT" > ~ISMODIF.BAT
ECHO SET NOWDATE=%%4> ENTER.BAT
CALL ~ISMODIF.BAT
IF "%NOWDATE%"=="%CHKDATE%" ECHO %1 was created or modified today

From http://www.robvanderwoude.com/bht.php .

0
source

Source: https://habr.com/ru/post/1757378/


All Articles