gpt4 book ai didi

sql-server - 使用 SSIS 压缩文件夹

转载 作者:行者123 更新时间:2023-12-04 02:04:35 24 4
gpt4 key购买 nike

我想在 SSIS 中压缩一个文件夹,源文件夹中有 12 个文件,我需要压缩那个文件夹。我可以很好地压缩文件,我的问题是文件夹。

我必须使用 winzip 来创建压缩包。

谁能给我指出一个好的教程。我无法实现我找到的任何示例。

谢谢

最佳答案

添加脚本任务,您可以使用 ZipFile(类)here reference ,您必须在项目(.NET Framework 4.5)中引用System.IO.Compression.FileSystem程序集。

您需要向脚本任务提供要压缩的文件夹和压缩文件夹的名称作为 ReadOnlyVariables(将添加到 ReadOnlyVariables 选项卡中)

这两个变量必须在包的Variables选项卡(String类型)中定义,并且可以通过循环动态更改(例如for each)

我使用这两个变量:

sFolderCompressed - the folder '.zip' that you want to obtain eg. C:\folder1\result.zip 
sFolderSource - the source folder containing the files affected eg. C:\folder1\folder2

enter image description here

脚本是用c#制作的,脚本语言选择:Microsoft Visual C#

enter image description here

这是要添加到 Main 方法中的代码:

using System.IO.Compression;

public void Main()
{
try
{
string zipPath = (string)Dts.Variables["User::sFolderCompressed"].Value;
string startPath = (string)Dts.Variables["User::sFolderSource"].Value;


ZipFile.CreateFromDirectory(startPath, zipPath);
}
catch (Exception objException)
{
Dts.TaskResult = (int)ScriptResults.Failure;
// Log the exception
}
Dts.TaskResult = (int)ScriptResults.Success;
}

希望能帮到你

关于sql-server - 使用 SSIS 压缩文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44416229/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com