解压一个 rar 文件 [英] Unpack a rar file

查看:22
本文介绍了解压一个 rar 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我搜索了可以让我解压文件的 dll 文件,我找到了很多,例如 unrar.dll、chilkat、sharpcompress 等等,但我想使用 Rar 提供的那个自己.

Okay, so I have searched for dll files that will allow me to unrar files and I was able to find quite a few such as unrar.dll, chilkat, sharpcompress and some more but I wanted to use the one provided by Rar themselves.

所以我在我的项目中引用了 DLL 文件并导入了它.我使用的是 unrar.dll.

So I referenced the DLL file in my project and imported it. I was using unrar.dll.

但是我找不到任何最新的代码来让我测试和尝试.我发现的所有示例要么不是最新的,要么不适用于 Vb.net.

But I wasn't able to find any up to date code to allow me to test and try things out. All the examples I found were either not up to date or not for Vb.net.

我也尝试了官方示例,它在安装中出现,但即使在我修复它之后也不起作用,当我尝试使用代码时,我总是遇到错误

I also tried the official example, which came in the installation but that didn't work even after I fixed it and when I tried to use the code I always got an error for

object reference not set to an instance of an object

我只想将特定位置的 rar 文件解压缩到我的程序的根目录,所以如果我的程序在桌面上,我希望它解压缩我的文档中的文件并将文件解压缩到我的桌面.

I just want to unrar a rar file from a specific location to the root directory of my program so if my program was on the desktop I want it to unrar a file in My documents and extract the files to my desktop.

推荐答案

如果您只想解压文件,我可以使用 SharpCompress

If you just want to unrar files, I Was able to do that with SharpCompress

首先,我创建了一个新的 VB.Net 应用程序,并在使用此代码从 Rar 文件中提取所有文件之前添加了对 SharpCompress.dll 的引用.

First I created a new VB.Net App and added a reference to SharpCompress.dll before using this code to extract all the files from a Rar file.

'Imports 
Imports SharpCompress.Archives
Imports SharpCompress.Common

'Unrar code
Dim archive As IArchive = ArchiveFactory.Open("C:\file.rar")

For Each entry In archive.Entries
    If Not entry.IsDirectory Then
        Console.WriteLine(entry.Key)
        entry.WriteToDirectory("C:\unrar", New ExtractionOptions With  
                              {.ExtractFullPath = True, .Overwrite = True})
    End If
Next

更多代码示例

这篇关于解压一个 rar 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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