Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Compare date and size of 2 files (DOS)

Posted on 2010-09-10
6
Medium Priority
?
844 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 1000 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 1000 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

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 58

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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

604 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