1
<Runtime.InteropServices.DllImport("tar32.dll")> _
Private Shared Function Tar(ByVal hwnd As IntPtr, _
ByVal szCmdLine As String, _
ByVal szOutput As String, _
ByVal dwSize As Long) As Integer
End Function
2
压缩一个文件
Public Shared Function ZipFile(ByVal zipFileName As String, ByVal sourceFile As String) As String
Try
Dim zipFilePath As String = System.IO.Path.GetDirectoryName(zipFileName)
Dim CommandString As String = "-c --display-dialog=0 --use-directory" & " " & _
zipFilePath & " " & zipFileName & " " & sourceFile
'TAR圧縮処理
Dim rtn As Long = 1L
rtn = Tar(CType(0, IntPtr), CommandString, Nothing, 0L)
If rtn <> 0L Then
Throw New System.Exception
End If
Return zipFileName
Catch ex As System.Exception
throw
End Try
End Function
3
压缩一个目录
Public Shared Function ZipFiles(ByVal zipFileName As String, ByVal sourceRootPath As String) As String
Try
If IsExist(zipFileName) Then
DeleteFile(zipFileName)
End If
Dim CommandString As String = "-c --display-dialog=0 --use-directory " & sourceRootPath & " " & zipFileName
Dim DestFiles() As String
DestFiles = GetFiles(sourceRootPath, "*.*")
For Each DestFile As String In DestFiles
CommandString = CommandString & " " & DestFile
Next
'TAR圧縮処理
Dim rtn As Long = 1L
rtn = Tar(CType(0, IntPtr), CommandString, Nothing, 0L)
If rtn <> 0L Then
Throw New System.Exception
End If
Return zipFileName
Catch ex As System.Exception
throw
End Try
End Function
4 解压
Public Shared Function Extract(ByVal sourceZipFile As String, _
ByVal destinationPath As String) As System.Collections.ArrayList
Try
Dim CommandString As String = "-x --display-dialog=0 " & sourceZipFile & " -o " & destinationPath
'TAR圧縮処理
Dim rtn As Long = 1L
rtn = Tar(CType(0, IntPtr), CommandString, Nothing, 0L)
If rtn <> 0L Then
Throw New System.Exception
End If
Dim DestFilesList As New System.Collections.ArrayList
Dim DestFiles() As String
DestFiles = GetFiles(destinationPath, "*.*")
For Each DestFile As String In DestFiles
If DestFile.Equals(sourceZipFile) Then
Continue For
End If
DestFilesList.Add(DestFile)
Next
Return DestFilesList
Catch ex As System.Exception
throw
End Try
End Function