压缩 (zip) 无法创建输出文件 - 错误 [英] Compressed (zip) Cannot create output file - error

查看:114
本文介绍了压缩 (zip) 无法创建输出文件 - 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 VBscript 来扫描文件夹、创建 zip 文件并向其中添加文件(压缩),但是当我在包含大量文件的文件夹上运行我的脚本时,出现以下错误:压缩(zip)无法创建输出文件"

I am using VBscript to scan folders, create zip files and add files to them (compress), but as I run my script on folders with a lot of files, I get the following error: "Compressed (zip) Cannot create output file"

我的邮政处理代码如下:

my zip handling code is as follows:

Dim objFSO
Set objFSO= CreateObject("Scripting.FileSystemObject"

Function PreformZip(objFile,target,zip_name, number_of_file)

  Set shell = CreateObject("WScript.Shell")  
  zip_target = target + "\" + zip_name +".zip" 
  If Not objFSO.FileExists(zip_target) Then
    MakePathIfNotExist(target) 
    NewZip(zip_target)
  Else
    If number_of_file=0 Then
        objFSO.DeleteFile(zip_target)
        NewZip(zip_target)
    End if
  End If

  Set zipApp = CreateObject("Shell.Application")
  aSourceName = Split(objFile, "\")
  sSourceName = (aSourceName(Ubound(aSourceName)))
  zip_file_count = zipApp.NameSpace(zip_target).items.Count
  zipApp.NameSpace(zip_target).Copyhere objFile, 16
  On Error Resume Next
  sLoop = 0
  Do Until zip_file_count < zipApp.NameSpace(zip_target).Items.Count
    Wscript.Sleep(100)
    sLoop = sLoop + 1
  Loop
  On Error GoTo 0
End Function

Sub NewZip(zip)
  Set new_zip = objFSO.CreateTextFile(zip)
  new_zip.Write Chr(80) & Chr(75) & Chr(5) & Chr(6) & String(18, 0)  
  new_zip.Close
  Set new_zip = Nothing 
  WScript.Sleep(5000)
End Sub

Function MakePathIfNotExist(DirPath)
Dim FSO, aDirectories, sCreateDirectory, iDirectory

Set FSO = CreateObject("Scripting.FileSystemObject")
If FSO.FolderExists(DirPath) Then
  Exit Function
End If

aDirectories = Split(DirPath, "\")
sCreateDirectory = aDirectories(0)
For iDirectory = 1 To UBound(aDirectories)
  sCreateDirectory = sCreateDirectory & "\" & aDirectories(iDirectory)
  If Not FSO.FolderExists(sCreateDirectory) Then
  FSO.CreateFolder(sCreateDirectory)
  End If
Next
End Function

Function Recursion(DirectoryPath)
Dim FSO : Set FSO = CreateObject("Scripting.FileSystemObject")

If FSO.FolderExists(DirectoryPath) Then Exit Function
Call Recursion(FSO.GetParentFolderName(DirectoryPath))
FSO.CreateFolder(DirectoryPath)
End Function

我一开始以为我在创建 zip 后等待的时间不够长,但我什至尝试在每个 zip 后等待 10 秒,但我仍然遇到相同的错误.

I first thought I'm not waiting long enough after creating the zip, but I even tried it with 10 seconds wait after each zip and I still get the same error.

我该如何解决?

如果没有解决方案,有没有其他方法可以制作zip?该脚本不仅供我自己使用,所以我不希望在需要安装的软件上进行 ro 中继?

If there is no solution, is there an alternative way to make a zip? The script is not only for my own use so I don't want ro relay on a software which needs to be installed?

推荐答案

好吧,经过大量的研究我发现在使用 shell 执行 zip 时没有可能的方法来解决这个问题.

Well, after a great amount of research I found out that there is no possible way to fix this problem when using shell to perform zip.

我通过以下方式使用 za7.exe (7-zip) 解决了这个问题:

I solved this issue by using za7.exe (7-zip) in the following way:

Dim zipParams 
zipParams = "a -tzip"
Dim objShell: Set objShell = CreateObject("WScript.Shell")  
command = zip_exe_location + " " + zipParams + " " + zip_target + " " + SourceFile
objShell.Run Command, 0 ,true 

zip 参数中的 "a" 表示添加到文件",-tzip 将文件类型设置为 zip.

the "a" in the zip parameters means "add to file" and -tzip sets the type of the file as zip.

这篇关于压缩 (zip) 无法创建输出文件 - 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆