Link to home
Start Free TrialLog in
Avatar of GGHC
GGHC

asked on

Batch Script to check date created of 2 exe. If source is newer, run command

I am looking to have a scheduled weekly task to run a script that will compare to .exes . If source is newer than run a setup command.  

It will be used on Windows 10 Pro PCs.
SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That sounds good.  I was thinking of suggesting xcopy before I saw Bill had already responded.  As you can use xcopy to copy a file if newer, I was thinking of using /L option to not copy but just say if it needed to copy, i.e.
xcopy /d /l /y file2.exe file1.exe

Open in new window

If file2.exe is newer than file1.exe then it will show the filename and 1 File(s) otherwise 0 File(s)

You could use that inside a script if wanted along the lines of:

xcopy /d /l /y file2.exe file1.exe | find /v "0 File" > NUL

Open in new window


The errorlevel from that of 1 would mean the files are the same, errorlevel 0 means do the copy

xcopy /d /l /y file2.exe file1.exe | find /v "0 File" > NUL && ECHO NEED TO COPY NEWER FILE

Open in new window

or
xcopy /d /l /y file2.exe file1.exe | find /v "0 File" > NUL
if errorlevel 0 ECHO NEED TO COP NEWER FILE

Open in new window


Bill's technique looks neater but that should work too if needed.

Steve
Avatar of GGHC
GGHC

ASKER

Nice!
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Change point split to:

    Bill Prew's comment #a41892972 (200 points)
    Bill Prew's comment #a41892355 (100 points)
    Steve Knight's comment #a41892624 (200 points)

~bp