Solved

Moving files upon creation

Posted on 2007-04-09
2
169 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

This article will show, step by step, how to integrate R code into a R Sweave document
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

717 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