Delete specified excel files using file system task inside foreach loop container

  • Hi All,

    I have to delete the existing 3 excel reports in a folder. The folder also contains other excel reports in it.

    For example, If i have to delete test1.xls, test2.xls and test3.xls. How should i hve to specify these file names in the foreach loop container and file system task for deletion?

    Please help me in resolving this......

    Priya

    Regards
    Priya

  • Do the files to be deleted have a specific name format? If yes, then you can the specify the wildcard format in for each loop enumerator.

    --Ramesh


  • Thanks for your response. It doesn't have any specified name format. All the 3 files have diff excel names.

    Priya

    Regards
    Priya

  • Use the "Foreach Loop Container" object.

    - Set the folder;

    - set the files (*.xls);

    - Retrieve file name = fully qualified;

    - In Variables Mapping, set a variable with index = 0;

    - in your excel connection manager, open the properties - Expression - ExcelFilePath. Set this property with the variable.

    - Set the excel connection in the file system task.

    Regards,

  • rfugikawa (1/21/2009)


    Use the "Foreach Loop Container" object.

    - Set the folder;

    - set the files (*.xls);

    - Retrieve file name = fully qualified;

    - In Variables Mapping, set a variable with index = 0;

    - in your excel connection manager, open the properties - Expression - ExcelFilePath. Set this property with the variable.

    - Set the excel connection in the file system task.

    Regards,

    This will consider all the *.xls file with in mention folder. She just want to delete particular files(specific ones).

    Abhijit - http://abhijitmore.wordpress.com

  • The question is how do systematically build up the list of files to delete. If you can do this, then you would create a variable that contains the list and use that as the source for the for each loop. Else you would hae to put the list of files in a table and create a variable for a result set of the table......

  • Thanks again. Is there any way by which the file names can be delimited and specified in a single variable, & that can be looped out for the list.... ?

    I m sorry if i m wrong but want to make it out......

    Priya

    Regards
    Priya

  • ...but the main question here is, how do you know which files needs to be deleted? The system cannot read your mind:D, and off course mine too..., you have to tell the system that these are the files that has to be deleted.

    As earlier suggested, you can specify the list of files in a table, and using execute sql task to load table into an object variable and pass this object to foreach loop container which in should call the file system task to delete that file.

    Other way around is that store the delimited file lists in a string variable and using Script Task, split the values and store it in Object variable.

    EDIT:

    As of now, I don't have any working sample that depict what I said. And if you can google it, you'll surely find samples on how to do it.

    --Ramesh


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

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