使用SSIS压缩文件夹

时间:2017-06-07 14:59:08

标签: sql-server ssis zip etl

我正在尝试在SSIS中压缩文件夹,源文件夹中有12个文件,我需要zipthat文件夹。我可以把文件拉得很好,我的问题就是文件夹。

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

任何人都可以指点我一个好的教程。我无法实现我找到的任何样本。

由于

3 个答案:

答案 0 :(得分:1)

尝试使用7zip它是免费的。看看7zip command line user guide它包含您需要的所有命令

使用脚本任务或执行流程任务来实现此目的。还有其他有用的链接:

更新1

您可以点击此链接获取winzip:

在上面的链接中,他们建议使用此命令:

 wzzip "c:\Test.zip" "c:\myfolder" -exPR

答案 1 :(得分:1)

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

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

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

我使用这两个变量:

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;
    }

我希望可以提供帮助。

答案 2 :(得分:0)

将这些东西写在bat文件中...... " C:\ Program Files \ WinZip \ WINZIP64.EXE" -a" C:\ Desktop \ destination_folder \ Sample.zip" " C:\桌面\ SAMPLE"

在执行流程任务中:

在执行流程任务 - >流程 - >可执行文件中提及bat文件的位置。

工作正常。

相关问题