script to copy files from one folder to another every hour

Posted on 2011-05-12
Last Modified: 2012-05-11
i am using windows server 2008

i want to run a script at startup that will copy folder a into folder b every hour.

for example:

C:/Folder A  copies to  C:/Documents/Folder B
at the following times:
01:00pm  etc.

so that any changes made to C:/Folder A between the hour will be transfered to
C:/Documents/Folder B every hour.

hope this is not too hard to do

Question by:webdott
    LVL 24

    Expert Comment

    by:Sekar Chinnakannu
    You can use robocopy, also check this

     Dim sOriginFolder, sDestinationFolder, sFile, oFSO
     Set oFSO = CreateObject("Scripting.FileSystemObject")
     sOriginFolder = "c:\tp"
     sDestinationFolder = "c:\tp2"
     For Each sFile In oFSO.GetFolder(sOriginFolder).Files
      If Not oFSO.FileExists(sDestinationFolder & "\" & oFSO.GetFileName(sFile)) Then
       oFSO.GetFile(sFile).Copy sDestinationFolder & "\" & oFSO.GetFileName(sFile),True
       WScript.Echo "Copying : " & Chr(34) & oFSO.GetFileName(sFile) & Chr(34) & " to " & sDestinationFolder
      End If
    LVL 10

    Expert Comment

    Whay not just adding your command line as a scheduled task that will be triggered every hour?
    LVL 10

    Accepted Solution

    Or if you absolutly want a script, here is an alternative to sekarc4u's solution

    ECHO %Date% Time% Copying in progress
    C:/Folder A  copies to  C:/Documents/Folder B
    ECHO %Date% Time% Copy completed
    CHOICE /D Y /T 3600 >NUL
    GOTO Home

    Author Comment


    does that script work on every hour? or just once manually?

    not sure how to do the task scheduler.
    i can see where to add the timer, but the action requites to start a program, send email, but not
    copy folder contents to folder contents

    LVL 26

    Assisted Solution

    The way to use the task scheduler is to create a little batch file that does the copying (like the one ReneGe suggested).  Then set the action of the task to be to run this batch file (that's the "program" you're looking for).  Now you can setup the schedule and run it whenever you want - e.g. ever hour.

    LVL 10

    Assisted Solution

    Yes, it will run at every 60minuts (3600 seconds) from the moment you start it.
    However, I use Task scheduler to do this kind of tasks.
    LVL 10

    Expert Comment

    W2008 choild have the command "choice" by defailt. To confirm you have it, open a command prompt and type "choice". If you get a "YN" response, you all good.

    Author Closing Comment

    thanks that works
    LVL 10

    Expert Comment

    Glad I could help

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
    You might have come across a situation when you have Exchange 2013 server in two different sites (Production and DR). After adding the Database copy in ECP console it displays Database copy status unknown for the DR exchange server. Issue is strange…
    This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

    729 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

    20 Experts available now in Live!

    Get 1:1 Help Now