Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1143
  • Last Modified:

Batch File to compare modified dates on 2 files

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
EWHTLC
Asked:
EWHTLC
1 Solution
 
oBdACommented:
Simply use xcopy.exe with the "/d" switch instead of "copy":
xcopy "\\server\share\file.txt" "C:\Temp\file.txt" /d
0
 
EWHTLCAuthor Commented:
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
 
oBdACommented:
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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
Bill PrewCommented:
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
 
EWHTLCAuthor Commented:
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
 
t0t0Commented:
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
 
EWHTLCAuthor Commented:
Indeed it does actually work.
Thank you very much
0
 
EWHTLCAuthor Commented:
sorry I ever doubted you
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Tackle projects and never again get stuck behind a technical roadblock.
Join Now