c# 解压 zip 文件

偶尔善良 提交于 2020-02-28 04:01:16
var fileName = GetPath(_tempFileName);
try
{
    File.Delete(fileName);
    File.Copy(_args[0], fileName);
    if (!File.Exists(fileName))
    {
        MessageBox.Show("Upgrade Failed, File Not Exist(升级失败,文件不存在).");
        return;
    }

    var startKey = "v2rayN/";

    using (ZipArchive archive = ZipFile.OpenRead(fileName))
    {
        foreach (ZipArchiveEntry entry in archive.Entries)
        {
            if (entry.Length == 0)
            {
                continue;
            }
            var fullName = entry.FullName;
            if (fullName.StartsWith(startKey))
            {
                fullName = fullName.Substring(startKey.Length, fullName.Length - startKey.Length);
            }

            string entryOuputPath = GetPath(fullName);

            FileInfo fileInfo = new FileInfo(entryOuputPath);
            fileInfo.Directory.Create();
            entry.ExtractToFile(entryOuputPath, true);
        }
    }
}
catch (Exception ex)
{
    MessageBox.Show("Upgrade Failed(升级失败)." + ex.StackTrace);
    return;
}
finally
{
    File.Delete(fileName);
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!