Solved

Compare date and size of 2 files (DOS)

Posted on 2010-09-10
6
837 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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:Richard Quadling
Richard Quadling 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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 55

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

691 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