Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Batch File to compare modified dates on 2 files

Posted on 2010-08-23
8
Medium Priority
?
1,139 Views
Last Modified: 2012-05-10
Hi,

I'm trying to create a batch file which will look at the modified date of  local file and compare the modified date to a file on a network location.
If the network location version is newer (based on the date modified) I would like to copy it to the local location

Is this possible?

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
8 Comments
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 total points
ID: 33500129
Simply use xcopy.exe with the "/d" switch instead of "copy":
xcopy "\\server\share\file.txt" "C:\Temp\file.txt" /d
0
 

Author Comment

by:EWHTLC
ID: 33500438
thanks for that.
What about the copy being dependent on the date modified?

imagine
c:\ss\filea                 date mod 23/082010 13:36
q:\loca\ss\filea         date mod 23/082010 14:36

In the above instance I would want tot vopy from file from q:\loca\ss\filea  to c:\ss\filea

however
c:\ss\filea                 date mod 23/082010 15:36
q:\loca\ss\filea         date mod 23/082010 14:36

in the above example I would not want tot do anything.

In summary in c:\ss (my local system) I always want the latest version of Filea

Hope this explains it better
0
 
LVL 85

Expert Comment

by:oBdA
ID: 33500509
xcopy's "/d" argument will do exactly this: it will only copy if the source file is newer:
Xcopy
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/xcopy.mspx?mfr=true
/d[:mm-dd-yyyy] : Copies source files changed on or after the specified date only. If you do not include a mm-dd-yyyy value, xcopy copies all Source files that are newer than existing Destination files. This command-line option allows you to update files that have changed.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 57

Expert Comment

by:Bill Prew
ID: 33500805
This feels like he may be trying to "flatten" a directory structure, and copy the newest version of a particular file that may exist multiple times in a tree of subfolders on the network into a single folder on the client.  I don't think there is a way to that with XCOPY, if that is indeed the case.  But maybe I am misunderstanding...

~bp
0
 

Author Comment

by:EWHTLC
ID: 33503286
From what oBdA is dsecribing I think it is what I want.
When a user runs the batch file they will actually load an Access database.
However, I might have been making changes to the database. Once I've finished I will drop my new version into a folder.
As the user run the batch file it will therefore identify a new version of the file and copy it locally.
I will then add into the batchfile the command line to actually run access and load my database etc.
It's basically a change control process for multiple users over a network. Not too sophisticated but it works

I'll need to try this out. So I'll be back as soon as I can

thanks again.
0
 
LVL 16

Expert Comment

by:t0t0
ID: 33505387
Just wondering if this works in a batch file?...


for %%a in ('dir /od /tw "c:\ss\filea" "q:\loca\ss\filea"') do (
   if "%%~da"=="q:" copy /y "q:\loca\ss\filea" "c:\ss\"
)
0
 

Author Closing Comment

by:EWHTLC
ID: 33511584
Indeed it does actually work.
Thank you very much
0
 

Author Comment

by:EWHTLC
ID: 33511588
sorry I ever doubted you
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

If your system is showing symptoms of browser hijacks or 'google search redirects' check out my other article (http://rdsrc.us/u3GP7A) first and run the tool TDSSKiller (http://rdsrc.us/GDBBs4) to get rid of the infection. Once done, and if the …
Step by step guide to Clean and Sort your windows registry! Introduction: Always remember: A Clean registry = Better performance = Save your invaluable time In this article we're going to clear our registry manually! Yes, manually! The e…
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…
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…
Suggested Courses

664 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