我试图制作一个压缩文件夹的程序,但是我一直得到一个NullReferenceException,它不创建所需的zip文件。我忘了什么东西吗?我正在使用Shell32,压缩子来自于一个代码项目教程。总之,这是代码:
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发布于 2014-02-22 00:52:18
下面是一个对我有用的例子:根据需要调整您的路径。诀窍是你必须先写出一个空白文件。
请参阅: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)https://stackoverflow.com/questions/21948025
复制相似问题