1.此方法压缩后,压缩包会保护文件所在全部目录
//zipFileName为目标压缩包路径(D:ss.zip)
ZipFile zipFile = ZipFile.Create(zipFileName)
zipFile.BeginUpdate();
zipFile.Add("D:\\xxx.txt");//此处用于添加文件
zipFile.CommitUpdate();
zipFile.Close();
2.上方法使用中会发现,CommitUpdate()时报错文件被占用,需加using
using (ZipFile zipFile = ZipFile.Create(zipFileName)) {
zipFile.BeginUpdate();
zipFile.Add("D:\\xxx.txt");
zipFile.CommitUpdate();
zipFile.Close();
}
3.解决压缩后目录过多问题
// sourceFolderPath需要压缩的文件夹路径
// destFolderPath压缩后的zip文件路径
public static bool CompressFolder(string sourceFolderPath, string destFolderPath)
{
try
{
//文件名=文件夹名+时间戳+.zip;
string zipFileName = destFol