Solved

Batch File to compare modified dates on 2 files

Posted on 2010-08-23
8
1,102 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 53

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

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Lock down IT Intern accounts 4 110
Exe program is not a valid Win 32 application 15 108
Batch FIle delete files with particular date 10 87
how to run this deletion request 4 20
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 …
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

786 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