WMI and moving files

  • Okay, maybe not a data warehousing question, but one for the SSIS geniuses out there.

    I have a situation where I need to watch a directory for files appearing and then processing them as they arrive. The WMI Event Watcher does a superb job for me in watching the directory and starting the package off - I know the window in which the files will arrive and can set a timeout.

    My problem is that one of the files I am expecting is quite substantial in size and I don't want to start processing it until it is all there.

    Easy, I thought. Wait for the WMI watcher to kick in and then move all of the files in the directory to another folder where I can process them, if the file is still being copied it will error on that one file (so I thought). I can record the error condition, process the files I have, and then return to check the directory again until either the error condition clears and I have the large file, the directory is empty, or a period of time has elapsed.

    I set my test up and was surprised to see the package run successfully and move the file - that was still copying - into the new location, removing it from the watched location. The file was incomplete, and two minutes later the file copy completed with no errors!!

    Is there any way, once the WMI has detected a file creation event, I can check to see whether the file I want to move has actually completed it's copy?

    Thanks in advance.


    ---------------------------------------
    It is by caffeine alone I set my mind in motion.
    It is by the Beans of Java that thoughts acquire speed,
    the hands acquire shaking, the shaking becomes a warning.
    It is by caffeine alone I set my mind in motion.

  • You could setup a script to watch the file for a period of time and see of the file size changes over that time, if it doesn't it could be considered complete if it does then start the wait again..

    I've never been particularly a fan of moving files around..

    CEWII

  • You could maybe try the File Watcher task as an alternative and see whether that works better for you.

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • Thanks Phil, the component does exactly what I need and has solved the issue admirably.


    ---------------------------------------
    It is by caffeine alone I set my mind in motion.
    It is by the Beans of Java that thoughts acquire speed,
    the hands acquire shaking, the shaking becomes a warning.
    It is by caffeine alone I set my mind in motion.

  • Splendid - thanks for posting back.

    Phil

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • Sounds like you are OK with the File Watcher Task, it's a good tool, but I figured I would throw in another option that will help accomplish the same but will not require the installation of a third party component. This one is based on the SSIS Script Task so you can modify the .NET source code in case you need additional functionality down the line:

    Using the Script Task in SSIS to Process Data Files When They Arrive[/url]

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • +1 for the File Wather on SQLIS. We use it all over the place. The 2005 version does not have a pretty config interface but still gets the job done. It needs installing on all dev machines and servers where it may be used.

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply