Advertisement

There's no such thing as a stupid question, but they're the easiest to answer.
Login
Search

Advertisement

Software Development Software Development
Search Search
Search for:
Tech Support Guy > > >

Solved: batch to compare file modified date with current date


(!)

dampyr's Avatar
dampyr dampyr is offline
Computer Specs
Member with 23 posts.
THREAD STARTER
 
Join Date: Nov 2011
Experience: Intermediate
05-May-2012, 09:29 AM #1
Solved: batch to compare file modified date with current date
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.
Intel_Xtreme's Avatar
Intel_Xtreme Intel_Xtreme is offline
Computer Specs
Member with 491 posts.
 
Join Date: Jan 2012
Experience: Advanced
06-May-2012, 07:14 AM #2
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's Avatar
dampyr dampyr is offline
Computer Specs
Member with 23 posts.
THREAD STARTER
 
Join Date: Nov 2011
Experience: Intermediate
06-May-2012, 07:24 AM #3
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?
Intel_Xtreme's Avatar
Intel_Xtreme Intel_Xtreme is offline
Computer Specs
Member with 491 posts.
 
Join Date: Jan 2012
Experience: Advanced
06-May-2012, 07:29 AM #4
Quote:
Originally Posted by dampyr View Post
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's Avatar
dampyr dampyr is offline
Computer Specs
Member with 23 posts.
THREAD STARTER
 
Join Date: Nov 2011
Experience: Intermediate
06-May-2012, 03:37 PM #5
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's Avatar
Trusted Advisor with 19,642 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
06-May-2012, 04:34 PM #6
Quote:
Originally Posted by dampyr View Post
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.
Quote:
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's Avatar
dampyr dampyr is offline
Computer Specs
Member with 23 posts.
THREAD STARTER
 
Join Date: Nov 2011
Experience: Intermediate
08-May-2012, 01:47 PM #7
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's Avatar
Trusted Advisor with 19,642 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
08-May-2012, 04:12 PM #8
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.
dampyr's Avatar
dampyr dampyr is offline
Computer Specs
Member with 23 posts.
THREAD STARTER
 
Join Date: Nov 2011
Experience: Intermediate
08-May-2012, 05:34 PM #9
All right,I will do that-thanks.
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine
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.


(clock)
THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


WELCOME
You Are Using: Server ID
Trusted Website Back to the Top ↑