Solved: batch to compare file modified date with current date

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

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.
 
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! :)
 

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?
 
Joined
Jan 7, 2012
Messages
491
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?
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.)
 

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 !
 

Squashman

Trusted Advisor
Joined
Apr 4, 2003
Messages
19,786
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 !
You said you wanted to match the date of files. This only works for Directories.
If you read the help for the FOR command.
FOR /D %variable IN (set) DO command [command-parameters]

If set contains wildcards, then specifies to match against directory
names instead of file names.
 

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
 

Squashman

Trusted Advisor
Joined
Apr 4, 2003
Messages
19,786
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.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

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 807,865 other people just like you!

Latest posts

Top