简体   繁体   中英

SSIS Delete files from folder based on a selection from SQL Database

I have an issue regarding a deletion of files based on a selection. So, I have an SQL table in which there is a column with the file name. What I have to do is take the file name from there and delete the physical file with that name from a specified path.

What I have tried is to execute an sql task with the selection of full file paths (including file names) which need to be deleted and store them in an object variable and then try to do a ForEach Loop Container with a 'from variable enumerator' to take those results and delete the files using a file system task, but I don't think that's the right approach. The execution of the package ends in success, but it ends at the ForEach Loop Container without reaching (executing) the file system task, so the files are not being deleted.

Select statement (also added the full path of the file as a column in order for the file system task to know where the physical file is stored):

select file_full_path from t1
where flag = 'YES'

Do you guys know a solution to this?

What you can do is set the loop to Foreach ADO Enumerator , so your process would be:

1: SQL Task - map file_full_path to an object variable, say 'filesdel'

在此处输入图像描述

2: Foreach Loop set to Foreach ADO Enumerator

在此处输入图像描述

3: Map the the the for loop items to a string variable, say 'filename':

在此处输入图像描述

4: Use the string variable in the File System Task

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM