我正在尝试在SSIS中压缩一个文件夹,源文件夹中有12个文件,我需要将该文件夹压缩。我可以成功压缩文件,但我的问题是文件夹。
我必须使用winzip创建压缩包。
有人可以指点我一个好的教程吗?我一直无法实现我找到的任何示例。
谢谢
我必须使用winzip创建压缩包。
有人可以指点我一个好的教程吗?我一直无法实现我找到的任何示例。
谢谢
添加一个脚本任务,您可以使用ZipFile(类)这里的参考资料,您必须在项目中引用System.IO.Compression.FileSystem程序集(.NET Framework 4.5)。
您需要将要压缩的文件夹和压缩后文件夹的名称作为ReadOnlyVariables提供给脚本任务(添加到ReadOnlyVariables选项卡中)
这两个变量必须在包的变量选项卡中定义(String类型),并且可以通过循环(例如,对于每个)动态更改。
我使用这两个变量:
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
脚本是用c#编写的,选择脚本语言:Microsoft Visual C#。
这是要添加到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;
}
我希望能够帮助。
尝试使用免费的7zip。查看7zip命令行用户指南,其中包含您需要的所有命令。
并使用脚本任务或执行进程任务来实现此目的。还有其他有用的链接:
更新 1
您可以通过此链接获取WinZip:
在上面的链接中,他们建议使用以下命令: wzzip "c:\Test.zip" "c:\myfolder" -exPR
在bat文件中编写以下内容...
"C:\Program Files\WinZip\WINZIP64.EXE" -a "C:\Desktop\destination_folder\Sample.zip" "C:\Desktop\Sample"
在执行进程任务中:
在执行进程任务中提及bat文件的位置-->进程-->可执行文件。
它可以正常工作。