Solved

Moving files upon creation

Posted on 2007-04-09
2
166 Views
Last Modified: 2011-09-20
We have a app that drops files a folder for processing.
I am looking to dupliate these files in another folder for redundancy.  We do have backups but have trouble with the files being opened and would like to add this method to increase the chance for successful recovery in case of problem.
Can we write a script to watch a folder for new fils and copy them to another folder on the server?
0
Comment
Question by:sher19
  • 2
2 Comments
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 18880243
This script will do just that...set it up to launch on startup (or logon) and it'll monitor the folder - the example below uses c:\scripts (listed as c:\\\\scripts)
It's set to poll every 10 seconds...adjust as necessary.

'WatchFolder.vbs
Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objWMI: Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
strTarget = "\\Servername\share\backup\"
Set colEvents = objWMI.ExecNotificationQuery _
    ("SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE " _
        & "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _
            & "TargetInstance.GroupComponent= " _
                & "'Win32_Directory.Name=""c:\\\\scripts""'")
Do
    Set objEvent = colEvents.NextEvent
    strNewFile = Replace(Mid(objEvent.TargetInstance.PartComponent, InStr(1, objEvent.TargetInstance.PartComponent, Chr(34))), "\\", "\")
    objFSO.CopyFile strNewFile, strTarget
Loop
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18880288
Happy to help - thanx! :^)
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

776 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