以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  在ft中如何改写这段代码?  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=185912)

--  作者:kgdce
--  发布时间:2023/3/24 17:42:00
--  在ft中如何改写这段代码?

C#(VB.NET) 压缩成zip包  

SharpZipLib第三方插件(开源免费)

Private Sub fileToZip(ByVal sourceDir As String, ByVal targetName As String)
\'sourceDir="D:\\test" 被压缩的文件夹路径。
If sourceDir.Length = 0 Then
    MessageBox.Show("Please specify a directory")
    Return
Else
    If Not Directory.Exists(sourceDir) Then
MessageBox.Show(sourceDir, "Directory not found")
Return
    End If
End If
 
\'targetName="D:\\test\\A.zip"指定压缩后的路径和文件夹。
If targetName.Length = 0 Then
    MessageBox.Show("No name specified", "Zip file name error")
    Return
End If
 
Dim astrFileNames() As String = Directory.GetFiles(sourceDir)
Dim strmZipOutputStream As ZipOutputStream
 
strmZipOutputStream = New ZipOutputStream(File.Create(targetName))
Try
 
    REM Compression Level: 0-9
    REM 0: no(Compression)
    REM 9: maximum compression
    strmZipOutputStream.SetLevel(9)
 
    Dim strFile As String
    Dim abyBuffer(4096) As Byte
 
    For Each strFile In astrFileNames
Dim strmFile As FileStream = File.OpenRead(strFile)
Try
 
    Dim objZipEntry As ZipEntry = New ZipEntry(Path.GetFileName(strFile))
    objZipEntry.DateTime = DateTime.Now
    objZipEntry.Size = strmFile.Length
 
    strmZipOutputStream.PutNextEntry(objZipEntry)
    StreamUtils.Copy(strmFile, strmZipOutputStream, abyBuffer)  黄色的不知道如何改写,请帮助!
Finally
    strmFile.Close()
End Try
    Next
 
    strmZipOutputStream.Finish()
Finally
    strmZipOutputStream.Close()
End Try
End Sub

--  作者:有点蓝
--  发布时间:2023/3/25 8:54:00
--  
看源码,写全命名空间即可

ICSharpCode.SharpZipLib.Core.StreamUtils.Copy(...........