Solved

Moving files upon creation

Posted on 2007-04-09
2
163 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
A quick step-by-step overview of installing and configuring Carbonite Server Backup.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
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…

705 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

17 Experts available now in Live!

Get 1:1 Help Now