private void Uncompress(object sender, RoutedEventArgs e){string zipPath = @"C:\Users\chaos\Desktop\res\download.zip"; // ZIP文件的路径string extractPath = @"C:\Users\chaos\Desktop\res\extract"; // 解压缩后文件存放的路径Console.Write(extractPath);try{using (ZipArchive archive = ZipFile.OpenRead(zipPath)){foreach (ZipArchiveEntry entry in archive.Entries){string tempname = entry.FullName.ToString();string destinationPath = System.IO.Path.Combine("", $"{extractPath}/{entry.FullName}"); //Console.WriteLine(destinationPath);if (entry.Name != ""){//创建文件所在的目录Directory.CreateDirectory(System.IO.Path.GetDirectoryName(destinationPath));entry.ExtractToFile(destinationPath);}}}// 解压缩文件//ZipFile.ExtractToDirectory(zipPath, extractPath);//Console.WriteLine("解压缩完成!");}catch (Exception ex){Console.WriteLine("解压缩失败:" + ex.Message);}}
注意
System.IO.Path.Combine(“”, $“{extractPath}/{entry.FullName}”); 尝试将路径合并,但是如果将extractPath 和 entry.FullName合并,只会保留后一个路径。
