压缩问题,大家多多帮忙!!

sinoghost 2005-08-04 05:37:16
刚刚看到ICSharpCode.SharpZipLib 开始用它压缩文件
可是总是出错,刚开始学习,很多东西不懂,请大家多多指教啊,先谢过了
我试图把几个文件压缩成一个文件,压出来的是一个错误文件

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim filenames(10) As String
Dim crs As New Crc32
Dim f As File
Dim fe As String
Dim s As ZipOutputStream = New ZipOutputStream(File.Create("G:\demoforzip\WindowsApplication1\bin\xx\model.zip"))
Dim i As Integer = 0
For i = 0 To 3
filenames(i) = ""
Next
filenames(0) = "G:\demoforzip\WindowsApplication1\bin\xx\a.txt"
filenames(1) = "G:\demoforzip\WindowsApplication1\bin\xx\b.txt"
filenames(2) = "G:\demoforzip\WindowsApplication1\bin\xx\c.txt"
filenames(3) = "G:\demoforzip\WindowsApplication1\bin\xx\d.txt"
s.SetLevel(6)
For Each fe In filenames
Dim fs As FileStream = File.OpenRead(fe)
Dim buffer() As Byte
fs.Read(buffer, 0, buffer.Length)
Dim entry As ZipEntry = New ZipEntry(fe)
entry.DateTime = DateTime.Now
entry.Size = fs.Length
fs.Close()
crs.Reset()
crs.Update(buffer)
entry.Crc = crs.Value
s.PutNextEntry(entry)
s.Write(buffer, 0, buffer.Length)
Next
s.Finish()
s.Close()

End Sub


多多指教
...全文
192 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
sinoghost 2005-10-07
  • 打赏
  • 举报
回复
这样能找到文件吗
sinoghost 2005-08-19
  • 打赏
  • 举报
回复
谢谢了,各位
ConanKid 2005-08-11
  • 打赏
  • 举报
回复
去掉前面的路径
filenames(0) = "a.txt"
filenames(1) = "b.txt"
filenames(2) = "c.txt"
filenames(3) = "d.txt"
把被压缩的文件,存放在与生成的压缩包同一目录下。
sinoghost 2005-08-08
  • 打赏
  • 举报
回复
压缩的时候,压缩文件的目录总是从根目录开始,怎样解决这个问题啊?如
我想压缩在 application.startuppath 路径下的 a.txt,b.txt文件

可是压缩后的文件被解压后的路径是
...../../../../application.startupPath/a.txt b.txt
ConanKid 2005-08-05
  • 打赏
  • 举报
回复
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim filenames(3) As String
Dim crs As New Crc32()
Dim f As File
Dim fe As String
Dim s As ZipOutputStream = New ZipOutputStream(File.Create(Me.GetApplicationPath() & "model.zip"))
Dim i As Integer = 0
For i = 0 To 3
filenames(i) = ""
Next
filenames(0) = "a.txt"
filenames(1) = "b.txt"
filenames(2) = "c.txt"
filenames(3) = "d.txt"
s.SetLevel(6)
For Each fe In filenames
Dim fs As FileStream = File.OpenRead(fe)
Dim buffer() As Byte = New Byte(fs.Length - 1) {}

fs.Read(buffer, 0, buffer.Length)
Dim entry As ZipEntry = New ZipEntry(fe)
entry.DateTime = DateTime.Now
entry.Size = fs.Length
fs.Close()
crs.Reset()
crs.Update(buffer)
entry.Crc = crs.Value
s.PutNextEntry(entry)
s.Write(buffer, 0, buffer.Length)
Next
s.Finish()
s.Close()

End Sub

Public Function GetApplicationPath() As String
Return IIf(Application.StartupPath.EndsWith("\"), Application.StartupPath, Application.StartupPath & "\")
End Function
sinoghost 2005-08-04
  • 打赏
  • 举报
回复
好着急啊,请多帮忙啊
sinoghost 2005-08-04
  • 打赏
  • 举报
回复
请多多指教!!!啊!!谢谢了

16,721

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧