How to use script task to check if file exists without knowing filename

  • I have created a package that takes a couple of .xml files, zips them and ftps them and then does some cleanup (moving to archive folder, etc). That all works great. But I am wanting to add a script prior to my For Each Loop Container to check and see if a *.xml file exists in the path or not. If it doesn't I want it to fail so I get proper notification that something is wrong since we should have a file every day. The problem is that the name of the files change so all I care about is that there is a *.xml file, not a specifically named file. I have tried using a file.exists statement in the script, but it seems to want an exact file name. I'm sure that there is something "simple" that I am not thinking about that will solve my problem.

    Any help is greatly appreciated.

  • Instead using a script task prior to your For Each Loop Container, here's what I'd do:

    1. Create a package level variable called FileCount (type int).

    2. Add a step inside of the For Each Loop Container to increment this counter (script task most likely).

    3. Add a send-mail task to the control flow downstream from the For Each container. Set the precedence constraint execute the send mail task when FileCount equals zero.

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • Thank you for your suggestion. I have found though that changing my script task to do the file.exists on the dir() function of that location it works and shows a success or failure as I would expect. For example:

    InFolder = CStr(Dts.Variables("User::InFolder").Value)

    DirPath = (Dir(InFolder & "*.xml"))

    If File.Exists(InFolder & DirPath) Then

    Dts.TaskResult = Dts.Results.Success

    Else

    Dts.TaskResult = Dts.Results.Failure

    End If

  • I assume then that you have your send mail task set up in the OnError event handler? That would work as well.

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

Viewing 4 posts - 1 through 3 (of 3 total)

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