Link to home
Start Free TrialLog in
Avatar of Eric Harris
Eric Harris

asked on

Compare date and size of 2 files (DOS)

Hi There,
I have s problem related to 2 physical sites (networked) where I work.
Files are replicated between the 2 sites. Sometimes, the replication fails, or is switched off.
The file (an excel file) is used and updated frequently between the 2 sites therefore making the replication very important in order not to miss updates performed at either end.

Short of redesigning the network I'm looking for a short term solution.
I thought maybe I would replace the file with a Batch file written in DOS which would compare the modified datetime, and the file sizes.
If the same then I would continue to open the excel file.
If different I would display a warning message containing the dates and the sizes depending on which was the newest etc, and then exit.

The DOS solution is quick and cheap solution to a real problem.
However, I'd be interested in any ideas.

Help would be appreciated
Avatar of compaqus
compaqus
Flag of Canada image

Change the paths here and it should work:
@echo off

fc /b e:\r.xls e:\temp\r.xls >nul&& goto :identical  

:different
echo THE FILES ARE DIFFERENT

set "filename=e:\r.xls"
for %%A in (%filename%) do echo.Size of "%%A" is %%~zA bytes
set "filename=e:\temp\r.xls"
for %%A in (%filename%) do echo.Size of "%%A" is %%~zA bytes

Pause

goto :EOF

:identical
echo the files are the same

start excel.exe r.xls

goto :EOF

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of compaqus
compaqus
Flag of Canada image

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
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
Avatar of Eric Harris
Eric Harris

ASKER

Both solutions are excellent.
I think the 1st solution only checks the file sizes. (apologies if I'm wrong)
THat would work in most cases unless it generated a file exactly the same size with changes in it.
Comparing the dates as well is the capture all solution.

However, I'm going to psplit the points as I believe that Compaqus would have enhanced the solution

THanks to both of you
A Brilliant response.
Avatar of Bill Prew
==> I think the 1st solution only checks the file sizes. (apologies if I'm wrong)

The first solution used FC which will actually compare the CONTENTS of the two files to make sure they are indeed identical.  So even if the date stamps were different, if the contents hadn't changed, it would report them as identical.  That may, or may not be what you want, just wanted to clarify.

~bp