您的位置:首页 > 编程语言 > C#

C#使用SevenZipSharp库时如何去掉压缩文件中的目录文件夹

2016-06-02 22:20 387 查看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
try
{
//注意区分项目是32位还是64位调用相应位的7z.dll.
SevenZip.SevenZipCompressor.SetLibraryPath("7z.dll");

SevenZip.SevenZipCompressor MyCompressor = new SevenZip.SevenZipCompressor();
//默认设置
MyCompressor.ArchiveFormat = SevenZip.OutArchiveFormat.SevenZip;
MyCompressor.CompressionMethod = SevenZip.CompressionMethod.Lzma;
MyCompressor.CompressionMode = SevenZip.CompressionMode.Create;
MyCompressor.ZipEncryptionMethod = SevenZip.ZipEncryptionMethod.Aes256;

//普通压缩压缩的文件带有文件夹,有时候使用不太方便
//MyCompressor.CompressFiles(@"data\text\1.txt.7z", @"data\text\1.txt");
//使用字典压缩,自定义格式
Dictionary<string, string> MyDic = new Dictionary<string, string>();
//key为压缩包中的文件名
//value为待压缩文件
MyDic["1.txt"] = @"data\text\1.txt";
MyCompressor.CompressFileDictionary(MyDic, @"data\text\1.txt.7z");//注意第二个参数为输出压缩包的文件
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息