Solved

Batch File to compare modified dates on 2 files

Posted on 2010-08-23
8
1,081 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
8 Comments
 
LVL 83

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 83

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
 
LVL 51

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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Can I legally transfer my OEM version of Windows to another PC?  (AKA - Can I put a new systemboard in my OEM PC?) Few of us are both IT and legal experts but we all have our own views of Microsoft's licensing rules and how they apply.  There are…
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

706 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

14 Experts available now in Live!

Get 1:1 Help Now