1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: batch to compare file modified date with current date

Discussion in 'Software Development' started by dampyr, May 5, 2012.

Thread Status:
Not open for further replies.
Advertisement
  1. dampyr

    dampyr Thread Starter

    Joined:
    Nov 25, 2011
    Messages:
    23
    hello to everybody

    I need batch code to check if date is modified in three files and that date should be compared with current date (%date%).If so,do some job,otherwise quit (exit /b)

    I found a bunch of solutions but what troubles me is date format.
    On my machine it is dd.mm.yyyy

    Thanks in advance.
     
  2. Intel_Xtreme

    Intel_Xtreme

    Joined:
    Jan 7, 2012
    Messages:
    491
    Depends on what your input program is.
    Most of the time for C++, C+, C* and LUA it's:
    local Clock = "os.date("%d.%m.%Y")" : "os.date("%s.%m.%H")"
    In code that the date and timestamp is needed, you would write "..Clock..".
    os.date("%d.%m.%Y")" is Date, Month, Year.
    os.date("%s.%m.%H")" is Seconds, Minutes, Hours.

    Hope this helps! :)
     
  3. dampyr

    dampyr Thread Starter

    Joined:
    Nov 25, 2011
    Messages:
    23
    Simply DOS batch file.What really confuses me is,for example:
    Code:
    For /F "Skip=1 Delims=" %%I In ('dir /b /OD file1.txt file2.txt')
    or:for /f "skip=5 tokens=1-5" %%i in ('dir /tc /a-d') do echo %%i %%m
    
    
    What i need to type to get data in desired format?
     
  4. Intel_Xtreme

    Intel_Xtreme

    Joined:
    Jan 7, 2012
    Messages:
    491
    Using the simple DIRLIST (in capitals) command may help.
    I haven't got much experience with cmd but I remember a couple of months ago I made a batch file that listed all the directories and files in the given folder- there's a function (think it might be /a or /e) that writes the date each file was modified- you could tell it to search the output text file and make it compare the dates.

    BTW- That doesn't look like DOS code to me- it looks like LUA (LUA is one of the few programming languages which has "do" as a function.)
     
  5. dampyr

    dampyr Thread Starter

    Joined:
    Nov 25, 2011
    Messages:
    23
    Code:
    @echo off
    setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
    for /D %%Q IN (*.*) DO (
      set FILETIME=%%~tQ
      if "!FILETIME:~0,10!"=="%DATE:~4%" echo %%Q
    )
    It seems that i found what i need.Thanks everyone for help !
     
  6. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,731
    You said you wanted to match the date of files. This only works for Directories.
    If you read the help for the FOR command.
     
  7. dampyr

    dampyr Thread Starter

    Joined:
    Nov 25, 2011
    Messages:
    23
    As always,Squashman was right,but finally,after some googling and try&errors i finally got working code:
    Code:
    @echo off
    set currentDate=%date%
    echo %date%>"C:\@IT\Izvestaji\Horeca & Traders to PDF\date.txt"
    SET filename="C:\@IT\Izvestaji\Horeca & Traders to PDF\horeca.pdf"
    FOR %%f IN (%filename%) DO SET filedatetime=%%~tf
    echo %filedatetime:~0, 10%>"C:\@IT\Izvestaji\Horeca & Traders to PDF\date1.txt"
    fc "C:\@IT\Izvestaji\Horeca & Traders to PDF\date.txt" "C:\@IT\Izvestaji\Horeca & Traders to PDF\date1.txt" > nul
    IF %ERRORLEVEL% NEQ 0 goto notsame else goto same
    :same
    echo Dates the same, do some code here
     
    :notsame
    echo Dates NOT the same, do some code here
     
    
     
  8. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,731
    Kind of over kill using those temporary files for the date. You should be able to hold dates in two variables and compare them just like you did in your initial script.
     
  9. dampyr

    dampyr Thread Starter

    Joined:
    Nov 25, 2011
    Messages:
    23
    All right,I will do that-thanks.
     
  10. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1052073