Solved

Compare date and size of 2 files (DOS)

Posted on 2010-09-10
6
808 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: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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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 53

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

815 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

9 Experts available now in Live!

Get 1:1 Help Now