//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:TEMPCLR.7z", @"C:UsersadminDesktopCLR.pdf", 10 * 1024 * 1024);
SevenZipDecompressFile(@"D:TEMPCLR.7z", @"d: empCLR");
//SevenZipCompressorFile(@"d:Temparch111.7z", @"d:Templog.txt", 1024 * 1024 * 10);
//SevenZipDecompressFile(@"d:Temparch111.7z", @"d: empaa1");
Console.WriteLine("6666");
Console.Read();
}
/// <summary>
/// SevenZipCompressorFile(@"d:Temparch111.7z", @"d:Templog.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=0)
{
SevenZipCompressor tmp = new SevenZipCompressor();
if (volumeSize > 0)
{
tmp.VolumeSize = volumeSize;
}
tmp.CompressFiles(compressAfterFileName,compressBeforeFileName);//CompressFiles
}
/// <summary>
/// 解压7z文件 Decompress7zFile(@"D:Tempaa.7z", @"d: empaa1");
/// </summary>
/// <param name="sevenzipFileName">要解压的7z文件在哪里如D:Tempaa.7z</param>
/// <param name="decompressFileToPath">解压到哪里如d: empaa1</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:UsersadminDesktopExport", @"d:Tempaa.7z");
/// </summary>
/// <param name="directoryPath">要压缩的目录如C:UsersadminDesktopExport</param>
/// <param name="compressToPath">压缩到哪里如d:Tempaa.7z</param>
/// <param name="VolumeSize">每个压缩文件的块大小如果文件较大,可能需要压缩为多个文件如 aa.7z.001,aa.7z.002</param>
public static void SevenZipCompressDirectory(string directoryPath,string compressToPath,int VolumeSize=0)
{
SevenZipCompressor tmp = new SevenZipCompressor();
if (VolumeSize > 0)
{
tmp.VolumeSize = 10 * 1024 * 1024;
}
tmp.CompressDirectory(directoryPath, compressToPath);
}
}
}