VB:从互联网下载 ZIP 文件(并解压)

发布于 2024-11-16 13:49:38 字数 756 浏览 1 评论 0原文

我需要使用 Visual Basic 从 Internet 下载 ZIP 文件。 这是我目前所拥有的:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim NewAppData As String
    NewAppData = Environment.ExpandEnvironmentVariables("%AppData%/.minecraft.zip")
    Call DownloadFile("http://blahblahbacksheep.co.cc/.minecraft.zip", NewAppData)
End Sub

当我调试程序时,它会给出以下信息:

Function 'DownloadFile' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.

我想要做的是下载 ZIP 文件,然后解压它。如果可能的话,显示带有百分比的标签,例如:

Downloaded: 100%
Extracting: 35%....

任何人都可以给我任何资源或编写一些代码来执行部分/全部操作吗?

谢谢

I need to somehow download a ZIP file from the internet using Visual Basic.
Here's what I currently have:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim NewAppData As String
    NewAppData = Environment.ExpandEnvironmentVariables("%AppData%/.minecraft.zip")
    Call DownloadFile("http://blahblahbacksheep.co.cc/.minecraft.zip", NewAppData)
End Sub

When I debug the program it gives me the following:

Function 'DownloadFile' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.

What I'm looking to do is download the ZIP file and then extract it. And if possible, show label's with percentage for example:

Downloaded: 100%
Extracting: 35%....

Could anyone give me any resources or write up a bit of code to do some/all of this?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

话少心凉 2024-11-23 13:49:39

对于您问题的解压缩部分: 7-Zip 是一个非常出色的开源文件归档实用程序有一个很好的命令行界面。下面是如何从 VB 调用 7-Zip 的示例(安装后):

Set WshShell = VBA.CreateObject("WScript.Shell")
WshShell.Run "c:\Program Files\7-Zip\7z.exe " & _
    "a -tzip myarchive.zip file.dat file2.txt file3.png", 1, True

此示例将三个文件压缩到一个存档中,而您想要从存档中提取文件...只需在文档。

请注意,7-Zip 执行时会弹出一个命令窗口,您将在其中看到一个 % 进度指示器。如果您希望此指示器出现在其他位置,那么只需一点点聪明才智,您可以将标准输出通过管道传输到其他相关位置。

For the unzipping part of your question: 7-Zip is a really great, open source, file archiving utility that has a nice command-line interface. Here's an example of how to call 7-Zip from VB (once it's been installed):

Set WshShell = VBA.CreateObject("WScript.Shell")
WshShell.Run "c:\Program Files\7-Zip\7z.exe " & _
    "a -tzip myarchive.zip file.dat file2.txt file3.png", 1, True

This example compresses three files into an archive, while you want to extract files from an archive... just look up the appropriate command for that in the documentation.

Note that a command window will pop up while 7-Zip is executing, and in there you'll see a % progress indicator. If you want this indicator to appear somewhere else, then with a bit of ingenuity you can probably pipe the standard output through to some other relevant location.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文