Solved

Compare date and size of 2 files (DOS)

Posted on 2010-09-10
6
787 Views
Last Modified: 2012-05-10
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
0
Comment
Question by:EWHTLC
6 Comments
 
LVL 7

Expert Comment

by:compaqus
ID: 33650468
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

0
 
LVL 7

Accepted Solution

by:
compaqus earned 250 total points
ID: 33650480
I have used 2 files named r.xls, one in e:\ and the other in e:\temp

at the "start excel.exe r.xls" also add the path, mine was in the same folder.

0
 
LVL 40

Assisted Solution

by:RQuadling
RQuadling earned 250 total points
ID: 33650629
Something along these lines ...


@ECHO OFF
FOR /F "tokens=1,2 delims=#" %%A IN ("%~1#%~2" ) DO (
      IF %%~tzA==%%~tzB (
            ECHO Files datetime and size match
      ) ELSE (
            ECHO Files datetime and size do not match
            ECHO %%~A %%~tA %%~zA
            ECHO %%~B %%~tB %%~zB
      )
)



test.bat file1.xls file2.xls

0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:EWHTLC
ID: 33650950
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
0
 

Author Closing Comment

by:EWHTLC
ID: 33650982
A Brilliant response.
0
 
LVL 51

Expert Comment

by:Bill Prew
ID: 33652922
==> 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
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Backup solution 14 71
Automated script task to send email 22 89
robocopy 6 50
how to find then copy to anotehr file 3 25
One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now