Foxtable(狐表)用户栏目专家坐堂 → [求助]zip文件流问题


  共有3666人关注过本帖树形打印复制链接

主题:[求助]zip文件流问题

帅哥哟,离线,有人找我吗?
zhutangxin
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:437 积分:3755 威望:0 精华:0 注册:2016/10/14 13:40:00
[求助]zip文件流问题  发帖心情 Post By:2021/11/17 1:38:00 [只看该作者]

老师您好,ZipFile有没有返回值,如何判断文件压缩已经压缩结束?

在写一个打包程序,需要将多个文件夹的文件按原来的目录结构放到zip文件中。写了一个内部函数,一次处理一个文件夹
形式代码如下:

Dim zip As New zipFile
zip.create or zip.open ...

for each fl as string in folder 
zip.addfile(fl, '路径/fl文件名')
next 
zip.close()

当需压缩多个文件夹时,需多次调用上述内部函数,如果前一个文件特别多时,会出现“流不支持写入”的报错。如果忽略,报错的文件夹没有把所有的文件压缩进去。
可能的原因是 zip.close 并不是zip已经结束,当下次再用 Dim zip As New zipFile 该压缩文件的时候,它将终止前面正在进行的压缩,从而报"流不支持写入"的错误。
有没有什么解决方法?


调用的目标发生了异常。
   在 System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   在 System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   在 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   在 Foxtable.UserFunctions.Execute(String Name, Object[] Args)
流不支持写入。
   在 System.IO.FileStream.SetLength(Int64 value)
   在 C1.C1Zip.d.a()
   在 C1.C1Zip.d.c()
   在 System.IO.Stream.Dispose()
   在 C1.C1Zip.C1ZipFile.a(Stream A_0, String A_1, DateTime A_2)
   在 C1.C1Zip.C1ZipFile.a(String A_0, String A_1, DateTime A_2)
   在 C1.C1Zip.C1ZipEntryCollection.Add(String fileName, String entryName, DateTime dateTime)
   在 C1.C1Zip.C1ZipEntryCollection.Add(String fileName, String entryName)
   在 Foxtable.ZipFile.AddFile(String Filename, String NewFileName)
   在 UserCode.AUo3pUozjTu0u80v5(Object[] Args)

 回到顶部
帅哥哟,离线,有人找我吗?
zhutangxin
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:437 积分:3755 威望:0 精华:0 注册:2016/10/14 13:40:00
  发帖心情 Post By:2021/11/17 4:00:00 [只看该作者]

用下述语句,也会出现报错,发现Publish\faces下的表情文件没有打包全。

Dim st As Date = Date.Today

Dim bakName As String = "Publish"

Dim f As String = ProjectPath + bakName  + CSTR(st).Replace("-","") +".zip"

If FileSys.FileExists(f) Then FileSys.DeleteFile(f)

 

Dim zip As new ZipFile

zip.Create(f)

zip.AddFolder(projectpath & "publish")

zip.Close


---------------------------
版本:2021.5.29.1
---------------------------
代码执行出错,错误信息:

System.NotSupportedException: 流不支持写入。
   在 System.IO.FileStream.SetLength(Int64 value)
   在 C1.C1Zip.d.a()
   在 C1.C1Zip.d.c()
   在 System.IO.Stream.Dispose()
   在 C1.C1Zip.C1ZipFile.a(Stream A_0, String A_1, DateTime A_2)
   在 C1.C1Zip.C1ZipFile.a(String A_0, String A_1, DateTime A_2)
   在 C1.C1Zip.C1ZipEntryCollection.Add(String fileName, String entryName, DateTime dateTime)
   在 C1.C1Zip.C1ZipEntryCollection.Add(String fileName, String entryName)
   在 C1.C1Zip.C1ZipEntryCollection.a(String A_0, String A_1, Boolean A_2, Int32 A_3)
   在 C1.C1Zip.C1ZipEntryCollection.a(String A_0, String A_1, Boolean A_2, Int32 A_3)
   在 C1.C1Zip.C1ZipEntryCollection.AddFolder(String path)
   在 UserCode.Test()
---------------------------
确定   
---------------------------

[此贴子已经被作者于2021/11/17 4:01:09编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:106680 积分:542589 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2021/11/17 8:58:00 [只看该作者]

我测试没有问题。应该是其它原因,比如杀毒软件,关闭所有杀毒软件试试。把Foxtable设置为使用管理员身份运行,检查publish目录里是否有隐藏的系统文件

 回到顶部
帅哥哟,离线,有人找我吗?
kgdce
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:620 积分:6782 威望:0 精华:0 注册:2013/12/17 1:00:00
  发帖心情 Post By:2023/3/24 10:58:00 [只看该作者]

经过测试,压缩的文件多时,会随机出现上述问题,和电脑的Cpu运算速度有关系,在一台笔记本电脑win10系统上用一直没问题,换到一个win7云桌面上用,就会有报错,调用的目标发生异常,流不支持写入。

 回到顶部