使用 7zip 检测文件是否为存档 [英] detecting if a file is an archive using 7zip

查看:59
本文介绍了使用 7zip 检测文件是否为存档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 SevenZipSharp 来确定文件是否为存档.我知道这是可能的,因为在资源管理器中,如果我将 .zip 重命名为 .bmp,7zip 仍会将其识别为存档.

I would like to use SevenZipSharp in order to determine if a file is an archive. I know that it's possible because in explorer if I rename a .zip to .bmp, 7zip still recognises it as an archive.

--edit:换句话说,我希望 7zip 告诉我文件(无论扩展名如何)是否包含某种受支持的存档(zip、tar、rar、iso 等)

--edit: In other words, I want 7zip to tell me if a file (no matter the extension) contains some kind of supported archive (zip, tar, rar, iso etc.)

谢谢,菲德尔

推荐答案

static bool IsArchive(string filename)
{
    bool result = false;
    try
    {
        new ArchiveFile(File.OpenRead(filename));
        result = true;
    }
    catch
    {
        //log if you're going to do something about it
    }
    return result;
}

这篇关于使用 7zip 检测文件是否为存档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆