Solved

Batch File to compare modified dates on 2 files

Posted on 2010-08-23
8
1,134 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 500 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 56

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Issue: Unstable cursor in Windows XP and Windows runs extremely slow in that any click will bring up the Hour glass (sometimes for several seconds before giving you what you want) . Troubleshooting Process and the FINAL FIX: This issue see…
If you have done a reformat of your hard drive and proceeded to do a successful Windows XP installation, you may notice that a choice between two operating systems when you start up the machine. Here is how to get rid of this: Click Start Clic…
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

623 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