0

I want to check a condition, if two files' modified dates have been updated to system's date, then trigger something. My code works, except %DATEONLY%==%SystemDate%==%ZipONLY% , this part has some issue, what is the right format for compare 3 Strings in Batch? or is there a way to separate them? Thanks ALL!!

@ECHO OFF
    FOR /f "tokens=1,2,3,4 delims=. " %%i in ('date /t') do set SystemDate=%%k%%j
    echo %SystemDate% is System Date
    pause


    FOR %%a IN (D:\MyFile.txt) DO SET FileDate=%%~ta
    set DATEONLY=%FileDate:~0,10%
    echo %DATEONLY% is Modified date
    pause


    FOR %%a IN (D:\Daildn.txt) DO SET ZipDate=%%~ta
    set ZipONLY=%ZipDate:~0,10%
    echo %ZipONLY%  is Modified date
    pause

    :CHECK
    if %DATEONLY%==%SystemDate%==%ZipONLY% (
    START C:\DailyRun.bat
    ) else (
    cls
    ECHO     Please Waiting for files to get ready 
    timeout /t 10 /nobreak
    GOTO :CHECK
    )
hben
  • 65
  • 1
  • 1
  • 9
  • `if %DATEONLY%==%SystemDate%==%ZipONLY%` => `if "%DATEONLY%" EQU "%SystemDate%" if "%DATEONLY%" EQU "%ZipONLY%"` – npocmaka Jul 21 '15 at 19:17
  • @hben, I strongly recommend that you remove the `cls` and the `@echo off` statements for script development, then you probably might already see what is going wrong... – aschipfl Jul 21 '15 at 20:24
  • @hben, what is the purpose of the first `for` statement? what do you receive when you enter `echo %date%` into the command prompt, and what is the value of `%FileDate%`? I'm asking because of your locale settings, which affect those outputs... – aschipfl Jul 21 '15 at 20:27
  • `if %DATEONLY%==%SystemDate%==%ZipONLY%` => `if "%DATEONLY%+%ZipONLY%" EQU "%SystemDate%+%SystemDate%"` – Aacini Jul 21 '15 at 20:34
  • Good idea, @Aacini. Though I recommend to use the comparison operator `==` here rather than `equ` in order to force string comparison. `equ` (as well as every other extended operator) tries to convert the expressions to numbers before the comparison, which might lead to unexpected results, because the date values are locale-dependent. – aschipfl Jul 21 '15 at 20:44
  • @aschipfl echo %date%, i think that is the fixed format to bring in system date. %FileDate% value is mm/dd/yyyy/ hour/minute – hben Jul 21 '15 at 20:49
  • No, @hben, the formats of `%date%` and `date /T` do depend on locale or region settings, like `%FileDate%` (`%%~ta`) does. Also the date format in the output of `dir` does... – aschipfl Jul 21 '15 at 20:56
  • @aschipfl: The conversion to numbers don't happen with "strings enclosed in quotes". I didn't used `==` since several years ago! **`;-)`** – Aacini Jul 21 '15 at 21:56
  • ...just for reference -- see also [this](http://stackoverflow.com/q/31527032/5047996), it's almost the same batch file... – aschipfl Jul 21 '15 at 22:25

0 Answers0