AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / computer / 问题 / 1470928
Accepted
techguy1029
techguy1029
Asked: 2019-08-14 10:57:16 +0800 CST2019-08-14 10:57:16 +0800 CST 2019-08-14 10:57:16 +0800 CST

7zip 只会压缩某些文件

  • 772

我有一个用于压缩旧文件并删除它们的脚本。该脚本在所有其他目录中工作正常,但一个特定目录将无法工作。它会尝试将其压缩,但最终只会创建一个名为 .zip 的空 zip 文件Program.7z。这让我觉得脚本中的空格没有被正确转义。我在我的路径中使用了双引号和单引号并检查了文件路径的串联。我还没有找到它可能是什么。有任何想法吗?

Const fileZillaLogs = "C:\Program Files (x86)\Server\Logs"
Const zipProgram = """C:\Program Files\7-Zip\7zG.exe"""
Const zipArgs = "a -mx9"
Dim intZipAge
intZipAge = 7
Dim intDelAge
intDelAge = 90


Call DeleteLogFiles(fileZillaLogs, intZipAge, intDelAge)



Function DeleteLogFiles(strLogPath, intZipAge, intDelAge)
  Const bDEBUG = True
  Dim objFs
  Dim objFolder
  Dim objSubFolder
  Dim objFile
  Dim objWShell
  Dim strCommand
  Dim iResult
  Set objWShell = CreateObject("WScript.Shell")
  Set objFs = CreateObject("Scripting.FileSystemObject")
  If Right(strLogPath, 1) <> "\" Then
    strLogPath = strLogPath & "\"
  End If
  If objFs.FolderExists(strLogPath) Then
    Set objFolder = objFs.GetFolder(strLogPath)
      For Each objSubFolder in objFolder.subFolders
        DeleteLogFiles strLogPath & objSubFolder.Name, intZipAge, intDelAge
      Next
      For Each objFile in objFolder.Files
        If bDebug Then wscript.echo vbTab & "reviewing file = " & strLogPath & objFile.Name
        If DateDiff("d",objFile.DateLastModified,Date) > intDelAge Then
          If bDebug Then wscript.echo "Deleting because its old" End If
          objFs.DeleteFile(strLogPath & objFile.Name)
        Else If DateDiff("d",objFile.DateLastModified,Date) > intZipAge _
          And (Right(objFile.Name, 4) = ".log") Then
            If bDebug Then wscript.echo vbTab & "zipping file = " & objFile.Path
            strCommand = zipProgram & " " & zipArgs & " " & objFile.Path & ".7z" & " " & objFile.Path
            iResult = objWShell.Run(strCommand, 0, "false")
            If bDebug Then wscript.echo vbTab & "zipping result = " & iResult
            If bDebug Then wscript.echo vbTab & "deleting file = " & strLogPath & objFile.Name
            objFs.DeleteFile(strLogPath & objFile.Name)
            End If
        End If
      Next
    Set objFs = Nothing
    Set objFolder = Nothing
    Set objWShell = nothing
  End If
End Function
command-line zip
  • 1 1 个回答
  • 49 Views

1 个回答

  • Voted
  1. Best Answer
    IronWilliamCash
    2019-08-14T11:46:19+08:002019-08-14T11:46:19+08:00

    您的问题在第 41 行。您的objFile.Path中有空格,但您将其添加到命令行参数。这意味着空格应该用引号引起来,但不能使用引号,因为它们用于连接字符串。然后,您必须转义应包含在最终结果字符串中的引号。在 VBS 中,转义字符是双引号字符。所以你的第 41 行应该是这样的:

    strCommand = zipProgram & " " & zipArgs & " " & """" & objFile.Path & ".7z" & """" & " " & """" & objFile.Path & """"
    

    注意 """" 序列,它们基本上是这样计算的:

    • 第一个双引号:字符串的开头
    • 第二个双引号:转义下一个字符
    • 第三个双引号:是您在最终字符串中想要的字符
    • 第四个双引号:字符串结尾

    我测试了它并且工作正常。两次使用objFile.Path函数时都必须转义。

    • 2

相关问题

  • 如何使用键盘快捷键在 macOS 终端中选择一行?

  • 如何在 macOS 的终端中切换切换(连续性)?

  • Windows 上是否有可以通过 CMD 或 Powershell 提供加密安全随机字节的设备或可执行文件?

  • Python 的“pass”参数的批处理等价物是什么?

  • 禁用后无法启用 Microsoft Print to PDF

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    Windows 10 服务称为 AarSvc_70f961。它是什么,我该如何禁用它?

    • 2 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Marko Smith

    ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败:无法获取本地颁发者证书 (_ssl.c:1056)

    • 4 个回答
  • Marko Smith

    我如何知道 Windows 安装在哪个驱动器上?

    • 6 个回答
  • Martin Hope
    Albin 支持结束后如何激活 WindowsXP? 2019-11-18 03:50:17 +0800 CST
  • Martin Hope
    fixer1234 “HTTPS Everywhere”仍然相关吗? 2019-10-27 18:06:25 +0800 CST
  • Martin Hope
    Kagaratsch Windows 10 删除大量小文件的速度非常慢。有什么办法可以加快速度吗? 2019-09-23 06:05:43 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    Inter Sys Ctrl+C 和 Ctrl+V 是如何工作的? 2019-05-15 02:51:21 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve