0

我试图制作一个压缩文件夹的程序,但我不断收到 NullReferenceException 并且它没有创建所需的 zip 文件。我忘记了什么吗?我正在使用 Shell32,zip 子来自 codeproject 教程。无论如何,这里是代码:

Imports System.IO
Imports Shell32
Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Me.Hide()
    Me.ShowInTaskbar = False
    Zip()
End Sub
Sub Zip()
    Dim sc As New Shell32.Shell()
    Dim input As Shell32.Folder = sc.NameSpace("C:\minercraft v2.0\")
    Dim output As Shell32.Folder = sc.NameSpace("C:\minercraft v2.0\backup.zip")
    output.CopyHere(input.Items, 4)
End Sub

End Class
4

1 回答 1

1

这是一个对我有用的示例:根据需要调整路径。诀窍是你必须先写出一个空白文件。

见: http: //www.codeproject.com/Tips/257193/Easily-zip-unzip-files-using-Windows-Shell32

  Dim sc As New Shell32.Shell()
  Dim startBuffer() As Byte = {80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, _
                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  ' Data for an empty zip file .
  FileIO.FileSystem.WriteAllBytes("C:\backup.zip", startBuffer, False)
  Dim input As Shell32.Folder = sc.NameSpace("C:\temp")
  Dim output As Shell32.Folder = sc.NameSpace("C:\backup.zip")
  output.CopyHere(input.Items, 4)
于 2014-02-22T00:52:18.977 回答