SSIS,file Exist and Package Exit

  • i have an SSIS package, that do some steps, where i nthe first one it try to move files from folder A to B.

    if there are no file that exist, the Job which run's the SSIS package,exit with an error.

    how can i in the SSIS end the package withought an error (and write to the event viewer that the SSIS has finished with no error beacuse no files were found)

    Thanks i nadvance

    peleg

  • Please provide more details. How are you attempting to move the files? etc

  • i am using a BAT file with a simple move command

  • Are you using a Foreach/File container?

    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.

  • no, just :

    MOVE /Y c:\x\*.txt c:\y\

  • I would recommend using a script task in SSIS. You can search on the FileSystemObject class... it has an Exists method for both files and folders.

    After searching on the class, if you would like to use it let me know what you are thinking of doing (english explanation of what you want the code to do) and I would be happy to provide some direction on writing the script task.

  • the FileSystemObject i know from vbscript, where do i find it in the SSIS?

    what i want to to is :

    if there are files in the Folder them move them from X to Y, and move the the next step in the SSIS.

    if there are NO file, then exit the SSIS, reporting of a ending the job but not on as failure (like it happens to me today).

    thanks

    Peleg

  • Phil Parkin (4/6/2009)


    Are you using a Foreach/File container?

    You might want to look at using the For Each container. You can configure it to only move the files it finds. If it does not find any then it does not try to move any.



    Alvin Ramard
    Memphis PASS Chapter[/url]

    All my SSC forum answers come with a money back guarantee. If you didn't like the answer then I'll gladly refund what you paid for it.

    For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • You might want to look at using the For Each container. You can configure it to only move the files it finds. If it does not find any then it does not try to move any.

    how do you do that?

    any way if there are no file i want to exit the SSIS and not continue, beacuse the next step depend's on that, that there files i nthe new folder!

  • I will have to agree with Alvin on this one. You can either create an Execute Process task to move from Folder A to folder B and then create a "For Each" task set to the Foreach File Enumerator linked to Folder B (see BOL for more info on this task) with your processing inside or you can create a "For Each" task to Folder A, process the file, and then move that specific file.

    FYI, when I move a file in a For Each loop I use a Script task with something like this:

    Public Sub Main()

    Dim f As New IO.FileInfo(Dts.Variables("TextFile").Value.ToString)

    If Not IO.Directory.Exists(Dts.Variables("ProcessedFolder").Value.ToString) Then

    IO.Directory.CreateDirectory(Dts.Variables("ProcessedFolder").Value.ToString)

    End If

    IO.File.Move(Dts.Variables.Item("TextFile").Value.ToString, Dts.Variables("ProcessedFolder").Value.ToString + "\" + f.Name)

    Dts.TaskResult = Dts.Results.Success

    End Sub

    Note: this will fail if anything has the file open.

  • Timothy J Hartford (4/6/2009)


    I will have to agree with Alvin on this one. You can either create an Execute Process task to move from Folder A to folder B and then create a "For Each" task set to the Foreach File Enumerator linked to Folder B (see BOL for more info on this task) with your processing inside or you can create a "For Each" task to Folder A, process the file, and then move that specific file.

    FYI, when I move a file in a For Each loop I use a Script task with something like this:

    Public Sub Main()

    Dim f As New IO.FileInfo(Dts.Variables("TextFile").Value.ToString)

    If Not IO.Directory.Exists(Dts.Variables("ProcessedFolder").Value.ToString) Then

    IO.Directory.CreateDirectory(Dts.Variables("ProcessedFolder").Value.ToString)

    End If

    IO.File.Move(Dts.Variables.Item("TextFile").Value.ToString, Dts.Variables("ProcessedFolder").Value.ToString + "\" + f.Name)

    Dts.TaskResult = Dts.Results.Success

    End Sub

    Note: this will fail if anything has the file open.

    You can use a File System Task to do the move. It requires much less programming. There's no need to use ActiveX or VB script for moving files anymore.



    Alvin Ramard
    Memphis PASS Chapter[/url]

    All my SSC forum answers come with a money back guarantee. If you didn't like the answer then I'll gladly refund what you paid for it.

    For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • You can? Oooh! I got to learn something new! Thanks, Alvin, I will have to give that a try (I have never noticed that task). Come from a programming background... but as always the first approach is seldom the best!

  • ok

    but if there are no file to move

    how can i prevent from the SSIS to go to the next step?

  • If your logic is in a for each loop than if there is no objects in the array nothing within that loop will be executed (0 items = execute 0 times).

  • peleg k (4/6/2009)


    ok

    but if there are no file to move

    how can i prevent from the SSIS to go to the next step?

    Inside the Foreach Loop Container, I would use a Script Task to increment the value of a variable each time the loop executes. Then I would use that variable in the Precedence Constraint and only go forward if the value is greater than 0.



    Alvin Ramard
    Memphis PASS Chapter[/url]

    All my SSC forum answers come with a money back guarantee. If you didn't like the answer then I'll gladly refund what you paid for it.

    For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]

Viewing 15 posts - 1 through 15 (of 22 total)

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