Script/command to copy File Daily

sarasotamac
sarasotamac used Ask the Experts™
on
Need a script or command to copy a file daily and move it to a directory on another server. The script needs to only copy the most recently created file in the directory.

Any ideas how to make this happen?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2014
Commented:
Kash2nd Line Engineer
Commented:
there are couple of ways you can do that.

you can use robocopy or secondly a batch script which can look like below:

copy C:\locationoffiles \\remotemachine\c$\Path\file

or may be use xcopy >>> http://en.kioskea.net/forum/affich-9894-batch-file-to-copy-file-from-one-system-to-on
Bill PrewIT / Software Engineering Consultant
Top Expert 2016
Commented:
This should do it:

@echo off
for /F "tokens=*" %%A in ('dir /b /a-d /tc /od "c:\source\*.*"') do (
  move "c:\source\%%~A" "\\server\sharename\folder"
  goto :Done
)
:Done

Open in new window

~bp
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

sarasotamacIT Manager

Author

Commented:
billprew, this is going to only copy the newest file, correct?
sarasotamacIT Manager

Author

Commented:
Kash, I was thinking of robocopy, as I have used it for large data migrations previously. My only concern is getting it to only move the newest file in the directory.
Kash2nd Line Engineer

Commented:
if I were you, i would create a PS scripts which would take inputs on how to proceed with data copy. It should not be that hard to create one with couple of hours on hand.

with regards to robocopy, you can modify the selection (files) to copy >>> http://technet.microsoft.com/en-us/library/cc733145.aspx
IT / Software Engineering Consultant
Top Expert 2016
Commented:
billprew, this is going to only copy the newest file, correct?

Correct.

~bp
sarasotamacIT Manager

Author

Commented:
Thanks everyone, I took a little from everyone's answers.
Bill PrewIT / Software Engineering Consultant
Top Expert 2016

Commented:
Welcome.

~bp

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start Today