//7z下载或者自己去找个地址 nurget,github之类的 链接:https://pan.baidu.com/s/1__dPu7X5b8Xr_ej9ya7Kdg 密码:q8nw
using SevenZip;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
//SevenZipCompressorFile(@"D:\TEMP\CLR.7z", @"C:\Users\admin\Desktop\CLR.pdf", 10 * 1024 * 1024);
SevenZipDecompressFile(@"D:\TEMP\CLR.7z", @"d:\temp\CLR\");
//SevenZipCompressorFile(@"d:\Temp\arch111.7z", @"d:\Temp\log.txt", 1024 * 1024 * 10);
//SevenZipDecompressFile(@"d:\Temp\arch111.7z", @"d:\temp\aa1\");
Console.WriteLine("");
Console.Read();
}
/// <summary>
/// SevenZipCompressorFile(@"d:\Temp\arch111.7z", @"d:\Temp\log.txt",1024*1024*10);
/// </summary>
/// <param name="compressAfterFileName"></param>
/// <param name="compressBeforeFileName"></param>
/// <param name="volumeSize"></param>
private static void SevenZipCompressorFile(string compressAfterFileName,string compressBeforeFileName,int volumeSize=)
{
SevenZipCompressor tmp = new SevenZipCompressor();
if (volumeSize > )
{
tmp.VolumeSize = volumeSize;
}
tmp.CompressFiles(compressAfterFileName,compressBeforeFileName);//CompressFiles
}
/// <summary>
/// 解压7z文件 Decompress7zFile(@"D:\Temp\aa.7z", @"d:\temp\aa1\");
/// </summary>
/// <param name="sevenzipFileName">要解压的7z文件在哪里如D:\Temp\aa.7z</param>
/// <param name="decompressFileToPath">解压到哪里如d:\temp\aa1\</param>
public static void SevenZipDecompressFile(string sevenzipFileName,string decompressFileToPath)
{
if (File.Exists(sevenzipFileName))
{
using (SevenZipExtractor tmp = new SevenZipExtractor(sevenzipFileName))
{
tmp.ExtractFiles(decompressFileToPath, tmp.ArchiveFileData.Select(x => x.Index).ToArray());
}
}
else if (File.Exists(sevenzipFileName+".001"))
{
using (SevenZipExtractor tmp = new SevenZipExtractor(sevenzipFileName+".001"))
{
tmp.ExtractFiles(decompressFileToPath, tmp.ArchiveFileData.Select(x => x.Index).ToArray());
}
}
}
/// <summary>
/// 7z压缩目录 CompressDirectory(@"C:\Users\admin\Desktop\Export", @"d:\Temp\aa.7z");
/// </summary>
/// <param name="directoryPath">要压缩的目录如C:\Users\admin\Desktop\Export</param>
/// <param name="compressToPath">压缩到哪里如d:\Temp\aa.7z</param>
/// <param name="VolumeSize">每个压缩文件的块大小如果文件较大,可能需要压缩为多个文件如 aa.7z.001,aa.7z.002</param>
public static void SevenZipCompressDirectory(string directoryPath,string compressToPath,int VolumeSize=)
{
SevenZipCompressor tmp = new SevenZipCompressor();
if (VolumeSize > )
{
tmp.VolumeSize = * * ;
}
tmp.CompressDirectory(directoryPath, compressToPath);
}
}
}