简体   繁体   English

SSIS 根据 SQL 数据库中的选择从文件夹中删除文件

[英]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.所以,我有一个 SQL 表,其中有一列带有文件名。 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.我尝试的是执行 sql 任务,选择需要删除的完整文件路径(包括文件名)并将它们存储在 object 变量中,然后尝试使用“来自变量枚举器”的 ForEach 循环容器获取这些结果并使用文件系统任务删除文件,但我认为这不是正确的方法。 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. package 的执行以成功结束,但它在 ForEach 循环容器处结束,没有到达(执行)文件系统任务,因此文件没有被删除。

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 语句(还添加了文件的完整路径作为列,以便文件系统任务知道物理文件的存储位置):

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:您可以做的是将循环设置为Foreach ADO Enumerator ,因此您的过程将是:

1: SQL Task - map file_full_path to an object variable, say 'filesdel' 1: SQL 任务 - map file_full_path 到 object 变量,比如“filesdel”

在此处输入图像描述

2: Foreach Loop set to Foreach ADO Enumerator 2:Foreach 循环设置为 Foreach ADO 枚举器

在此处输入图像描述

3: Map the the the for loop items to a string variable, say 'filename': 3:Map for 循环项到一个字符串变量,比如'filename':

在此处输入图像描述

4: Use the string variable in the File System Task 4:在文件系统任务中使用字符串变量

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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