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

查看:115
本文介绍了使用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.)

谢谢, 菲德尔(Fidel)

Thanks, Fidel

推荐答案

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天全站免登陆