duheng
2024-06-25 43e88ef24c6b3a7988c495d1740e68e33ce52f84
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System.IO;
using System.IO.Compression;
 
namespace HStation.WinFrmUI.Xhs.Project
{
    public class ExtractHelper
    {
        public static void ExractFile(string FilePath)
        {
            string extractPath = @"C:\Users\ZKC\Desktop\sss";
            if (!Directory.Exists(extractPath))
            {
                Directory.CreateDirectory(extractPath);
            }
            using (ZipArchive archive = ZipFile.OpenRead(FilePath))
            {
                foreach (ZipArchiveEntry entry in archive.Entries)
                {
                    string destinationPath = Path.Combine(extractPath, entry.FullName);
                    if (entry.Length == 0)
                    {
                        Directory.CreateDirectory(destinationPath);
                    }
                    else
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(destinationPath));
                        using (FileStream stream = File.Create(destinationPath))
                        {
                            entry.Open().CopyTo(stream);
                        }
                    }
                }
            }
        }
    }
}