batch to check if a single file is modified

July 29, 2010 at 17:41:05
Specs: Windows XP
I have to check in an external directory if a single file (example.avi) is modified/create today and if the answer is yes start another batch or quit.

I've found several posts but I'm not be able to make this batch file from myself.

I hope someone can help me.
Thank you in advance.

See More: batch to check if a single file is modified

Report •

July 29, 2010 at 19:53:31
download coreutils and use md5sum

C:\test> md5sum file  > baseline.txt

save it to a file called baseline.txt for example. then on the next round of checking, get the md5sum from the file, and check against the md5sum to see if its changed.

GNU win32 packages | Gawk

Report •

July 30, 2010 at 06:44:34
Thank You for the reply, but I need to do this with an automatic batch at prefixed time one time a day.

Report •

July 31, 2010 at 08:03:57
I've found this but does not work on my 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

Report •

Related Solutions

August 1, 2010 at 00:57:39
Try this - not fully tested. Assumes that the date returned by %date% is in the form Sun 08/01/2010

@echo off
setlocal enabledelayedexpansion

set file=example.avi

:: Get date written of input file
for /f "tokens=1*" %%1 in ('dir /b /tw %file%') do (
    set filedate=%%~t1&set filedate=!filedate:~0,10!

:: Get today's system date
for /f "tokens=2" %%1 in ('echo %date%') do (
    set systemdate=%%1

:: Compare dates and display result
if %filedate% neq %systemdate% (
   echo %file% was not written today.&exit /b
   ) else (
   REM after testing change the following line to call the wanted .bat file
   echo %file% was written today.

Report •

August 1, 2010 at 06:51:34
First of all Thanks...

I entered the path to the file otherwise it said file not found.

The result from the command line is: 10 not expected.
and I don't know what it meaning...

My date format is: DD/MM/YYYY

Report •

August 1, 2010 at 16:30:45
solution based on my system Win XP where the date is in the format: DD/MM/YYYY

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

Report •

Ask Question