Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Moving files upon creation

Posted on 2007-04-09
2
Medium Priority
?
173 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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Suggested Courses

636 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