tar32.dll解压,压缩

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

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值